Find the answer to your Linux question:
Results 1 to 2 of 2
ok i posted this somewhere else for a specific issue, but just to see what kind of knowledge i can learn, if you want, fix this script or make it ...
  1. #1
    Just Joined!
    Join Date
    Nov 2006
    Posts
    90

    fix windows registry with a bash script

    ok i posted this somewhere else for a specific issue, but just to see what kind of knowledge i can learn, if you want, fix this script or make it better. i wll take your changes and integrate them into a pc toolkit im building and then put it on the web as source, but this is mainly to learn stuff the best way that i learn. this is the code, post changes back here or leave a note for a email address to put them in::::::



    echo "This is a safe semi-automatic script for fixing the 2000 and xp registry"
    echo "it requires that restore points exist and that we are building off a standard-named win"
    echo "directory structure (eg. c:/windows/system32/config etc...)"
    echo
    echo "Please locate and press the 'any' key..."

    clear
    echo "Please tell me which drive contains Windows"
    echo
    fdisk -l
    echo
    echo
    echo "the one with the star under boot is with the NTFS file structure is"
    echo "most likely the Windows drive. this is not always gospel"
    echo "as the boot drive may change, or there may be more than one"
    echo "NTFS file structure present, or a FAT32 (VFAT) drive such as win98."
    echo "If in doubt, please consult a senior tech that knows bugspray well"
    echo -n "type in the drive with windows on it (eg sda1) " && read winblows

    if [ ! -e /mnt/$winblows/ ]
    then echo "hmmm... cant see windows here. are you sure "$winblows" was what you meant to select?" && sleep 5s && /run/reboot && exit 435
    fi

    if [ -e /tmp/lalst.txt ];
    then rm -f /tmp/lalst.txt
    fi

    echo " please locate the restore folder to back up from out of the list below." > /tmp/lalst.txt
    echo " it is best to choose one that is about third newest" >> /tmp/lalst.txt
    echo " when you have made your choice, press q" >> /tmp/lalst.txt
    echo " and you will be prompted to enter it" >> /tmp/lalst.txt
    echo " After that, the process should finish on its own" >> /tmp/lalst.txt
    echo " and should not take very long." >> /tmp/lalst.txt
    la /mnt/$winblows/System\ Volume\ Information/_Restore/ >> /tmp/lalst.txt
    cat /tmp/lalst | less
    echo -n "tell me which folder you have chosen (eg. RP154)"

    read RP

    if [ ! -e /mnt/$windows/System\ Volume\ Information/_Restore/$RP/ ];
    then echo "hmm... cant see restore folder "$RP". Are you sure that is the correct number?" && sleep 5s && /run/reboot && exit 439
    fi


    clear
    echo "backing up current registry to c:/windows/system32/regbaks/"
    echo "IF you run this script twice, it will overwrite the old backups!!!"
    echo
    echo


    mkdir /mnt/$windows/Windows/system32/regbacks/

    mv /mnt/$windows/Windows/system32/config/software /mnt/$windows/system32/regbaks/ -vf || echo "COULD NOT BACK UP REGISTRY, CALLING PANIC!!!" && /run/reboot && sleep 3s && exit 436
    mv /mnt/$windows/Windows/system32/config/sam /mnt/$windows/system32/regbaks/ -vf || echo "COULD NOT BACK UP REGISTRY, CALLING PANIC!!!" && /run/reboot && sleep 3s && exit 436
    mv /mnt/$windows/Windows/system32/config/system /mnt/$windows/system32/regbaks/ -vf || echo "COULD NOT BACK UP REGISTRY, CALLING PANIC!!!" && /run/reboot && sleep 3s && exit 436
    mv /mnt/$windows/Windows/system32/config/security /mnt/$windows/system32/regbaks/ -vf || echo "COULD NOT BACK UP REGISTRY, CALLING PANIC!!!" && /run/reboot && sleep 3s && exit 436


    echo "backup complete"
    echo
    echo
    echo " removing old registry files"
    echo
    echo
    rm /mnt/$windows/Windows/system32/config/software -vf || echo "could not delete old registry, calling panic!!!" && /run/reboot && sleep 3s && exit 438
    rm /mnt/$windows/Windows/system32/config/sam -vf || echo "could not delete old registry, calling panic!!!" && /run/reboot && sleep 3s && exit 438
    rm /mnt/$windows/Windows/system32/config/system-vf || echo "could not delete old registry, calling panic!!!" && /run/reboot && sleep 3s && exit 438
    rm /mnt/$windows/Windows/system32/config/security -vf || echo "could not delete old registry, calling panic!!!" && /run/reboot && sleep 3s && exit 438

    echo "completed removing old files, installing backup files"
    echo
    echo

    cp /mnt/$windows/System\ Volume\ Information/_Restore/$RP/snapshot/_REGISTRY_MACHINE_SOFTWARE /mnt/$windows/Windows/system32/config/software || echo "restore file installation failed. restarting..." && sleep 5s && /run/reboot && exit 437
    cp /mnt/$windows/System\ Volume\ Information/_Restore/$RP/snapshot/_REGISTRY_MACHINE_SAM /mnt/$windows/Windows/system32/config/sam || echo "restore file installation failed. restarting..." && sleep 5s && /run/reboot && exit 437
    cp /mnt/$windows/System\ Volume\ Information/_Restore/$RP/snapshot/_REGISTRY_MACHINE_SYSTEM /mnt/$windows/Windows/system32/config/system || echo "restore file installation failed. restarting..." && sleep 5s && /run/reboot && exit 437
    cp /mnt/$windows/System\ Volume\ Information/_Restore/$RP/snapshot/_REGISTRY_MACHINE_SECURITY /mnt/$windows/Windows/system32/config/security || echo "restore failed. restarting..." && sleep 5s && /run/reboot && exit 437
    clear

    echo "backup succeeded. reboot to windows and see if it worked. "
    echo "if not, try an earlier registry backup, but not more than about a month old"

  2. #2
    Just Joined!
    Join Date
    Apr 2005
    Location
    NC, USA
    Posts
    43

    here

    Overall I'd say you were pretty close - so not bad.

    here's one that actually works though! Hope it's useful to somebody besides myself.

    Code:
    #!/bin/bash
     echo "This is a safe semi-automatic script for fixing the 2000 and xp registry."
     echo "It requires that restore points exist and that we are building off a standard-named win"
     echo "directory structure (eg. c:/windows/system32/config etc...)"
     echo
     echo "Please locate and press the 'any' key..."
     echo
     echo
     echo "Please tell me which drive contains Windows"
     echo
     fdisk -l | grep NTFS
     fdisk -l | grep FAT
     echo
     echo
     echo "The one with the star under boot with the NTFS file structure is"
     echo "most likely the Windows drive. This is not always gospel"
     echo "as the boot drive may change, or there may be more than one"
     echo "NTFS file structure present, or it could be FAT32." 
     echo "If in doubt, please consult a level 3 or higher mage."
     echo
     echo -n "Type the drive where Windows is located (eg sda1): " && read windows
     
     if [ ! -e /mnt/$windows/Windows ]
     then echo "hmmm... cant see windows here. are you sure "$windows" was what you meant to select?" && sleep 5s && exit 435
     fi
     
     echo " Please locate the restore folder to back up from out of the list below."
     echo " It is usually best to choose one that is about third newest."
    echo
     ls /mnt/sda1/System\ Volume\ Information/_restore* | grep RP*
    echo
     echo -n "Which folder would you like to restore from? (eg. RP154): "
     
     read RP
     
    restore='ls /mnt/sda1/System\ Volume\ Information | grep restore'
    
     if [ ! -e /mnt/$windows/System\ Volume\ Information/$restore/$RP/ ];
     then echo "Hmm... cant see restore folder "$RP". Are you sure that is the correct number?" && sleep 5s && exit 439
     fi
     
     
     clear
     echo "Backing up current registry to C:/windows/system32/regbaks/"
     echo "If you run this script twice, it WILL overwrite the old backups!!!"
     echo
     echo
     
     
     mkdir /mnt/$windows/Windows/system32/regbacks/
     
     mv /mnt/$windows/Windows/system32/config/software /mnt/$windows/system32/regbaks/ -vf || echo "COULD NOT BACK UP REGISTRY, CALLING PANIC!!!" && sleep 3s && exit 436
     mv /mnt/$windows/Windows/system32/config/sam /mnt/$windows/system32/regbaks/ -vf || echo "COULD NOT BACK UP REGISTRY, CALLING PANIC!!!" && sleep 3s && exit 436
     mv /mnt/$windows/Windows/system32/config/system /mnt/$windows/system32/regbaks/ -vf || echo "COULD NOT BACK UP REGISTRY, CALLING PANIC!!!" && sleep 3s && exit 436
     mv /mnt/$windows/Windows/system32/config/security /mnt/$windows/system32/regbaks/ -vf || echo "COULD NOT BACK UP REGISTRY, CALLING PANIC!!!" && sleep 3s && exit 436
     
     
     echo "Backup complete."
     echo
     echo
     echo "Removing old registry files"
     echo
     echo
     rm /mnt/$windows/Windows/system32/config/software -vf || echo "could not delete old registry, calling panic!!!" && sleep 3s && exit 438
     rm /mnt/$windows/Windows/system32/config/sam -vf || echo "could not delete old registry, calling panic!!!" && sleep 3s && exit 438
     rm /mnt/$windows/Windows/system32/config/system-vf || echo "could not delete old registry, calling panic!!!" && sleep 3s && exit 438
     rm /mnt/$windows/Windows/system32/config/security -vf || echo "could not delete old registry, calling panic!!!" && sleep 3s && exit 438 
     
     echo "Completed removing old files, installing backup files"
     echo
     echo
     
     cp /mnt/$windows/System\ Volume\ Information/$restore/$RP/snapshot/_REGISTRY_MACHINE_SOFTWARE /mnt/$windows/Windows/system32/config/software || echo "restore file installation failed. restarting..." && sleep 5s && exit 437
     cp /mnt/$windows/System\ Volume\ Information/$restore/$RP/snapshot/_REGISTRY_MACHINE_SAM /mnt/$windows/Windows/system32/config/sam || echo "restore file installation failed. restarting..." && sleep 5s && exit 437
     cp /mnt/$windows/System\ Volume\ Information/$restore/$RP/snapshot/_REGISTRY_MACHINE_SYSTEM /mnt/$windows/Windows/system32/config/system || echo "restore file installation failed. restarting..." && sleep 5s && exit 437
     cp /mnt/$windows/System\ Volume\ Information/$restore/$RP/snapshot/_REGISTRY_MACHINE_SECURITY /mnt/$windows/Windows/system32/config/security || echo "restore failed. restarting..." && sleep 5s && exit 437
     clear
     
     echo "Backup succeeded. reboot to windows and see if it worked. "
     echo "If not, try an earlier registry backup, but not more than about a month old"
     read -n1 foo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...