Find the answer to your Linux question:
Results 1 to 6 of 6
um.... bad title I need to know how to make a snippet of bash code that will look on "sda2" and tell me what the name of the _restore{??????????????????} is ...
  1. #1
    Just Joined!
    Join Date
    Nov 2006
    Posts
    90

    how to make a variable out of a dynamic folder name

    um.... bad title


    I need to know how to make a snippet of bash code that will look on "sda2"
    and tell me what the name of the _restore{??????????????????} is

    like i need to be able to have the script find system\ volume\ information/_restore{??????????????????????????????}

    in which {??????????????????????????????????} is different but the same lenth all the time, from pc to pc. i need to have this be

    $restorefol

    can cat | grep be used? how?

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,695
    Google: linux find command

    Find Tutorial

  3. #3
    Just Joined!
    Join Date
    Nov 2006
    Posts
    90
    google dont fix all problems. been working on this prob for 3 weeks. i can get the info, but until i understand how it works and such, i cant use it at work


    is "google it" the new RTFM?

    btw, this is why i need info (dont laugh at my code plz )

    "fixreg" ) # fix registry

    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"
    read -n1 foo
    ;;
    Last edited by jwmw1023; 03-11-2008 at 08:13 PM. Reason: added code snippet

  4. #4
    Just Joined!
    Join Date
    Apr 2005
    Location
    NC, USA
    Posts
    43
    Posted it on the other thread too, but whatever...

    Thanks for the idea/basis. Your general outline really saved me some time. I hope I save somebody else some time as well.

    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

  5. #5
    Just Joined!
    Join Date
    Nov 2006
    Posts
    90
    THANK YOU VERY MUCH!!!

    this is for a multi-purpose utility at work that does many computer related things. this has been bugging me for a while. If you want, Ill email you the whole thing to view, some works well, some of it does not.

    thanks again

    --kainalu

  6. #6
    Just Joined!
    Join Date
    Apr 2005
    Location
    NC, USA
    Posts
    43
    Sure! I'm actually working on turning Slax into a complete Windows repair utility.

    I'm not sure what kind of work you do, so it may not be useful, but I have some quick and dirty scripts for checking NTFS filesystems, creating/writing disk images, fixing the MBR, recovering partition tables, and undeleting files from NTFS.

    I'll PM you my email if you'd like to exchange notes.

Posting Permissions

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