Sudo Command in Bash Script

So I created a simple bash script to run on login.....
one of the commands is the following:
sudo "something something something"....
One thing I haven't learned in my years of Unix is how do you get a bash script to run a sudo command without having to enter a password?  I know this is trival, but just a quick 'this is how you do it' would be cool.
Thanks ahead of time on this really dumb question.

There's a few ways to do this.  Here's two (pick the method you like):
Method 1: Using "askpass".
With this you always do sudo -A command.  The -A argument tells sudo to execute a command that echos the password to stdout.  That command is something you write.  For this explaination let's call the command pw and stick it /usr/local/bin.  So it's full pathname would be /usr/local/bin/pw.
sudo -A can get the pathname to pw a number of ways.
1. From the sudoers file.
Use visudo to add the following line to the sudoers file:
Defaults:ALL    askpass=/usr/local/bin/pw
2. Using the SUDO_ASKPASS environment variable.
export SUDO_ASKPASS=/usr/local/bin/pw
This might work too (assuming SUDO_ASKPASS has been previously exported):
SUDO_ASKPASS=/usr/local/bin/pw sudo -A command
Method 2: Have sudo read the password from stdin
echo -n password | sudo -S command
The -S option tells sudo to read the password from stdin so echo pipes it in (without the ending newline).
The only relatively secure scheme of these two methods is the askpass (-A) method.  At least with that method you have a chance of encrypting/hiding your password down in the command that echoes it to stdout.  The -S method would contain your password explicitly in a script somewhere unless you make other provisions to encrypt/hide it with that technique.

Similar Messages

  • [SOLVED] problem with spaces and ls command in bash script

    I am going mad with a bash script I am trying to finish. The ls command is driving me mad with spaces in path names. This is the portion of my script that is giving me trouble:
    HOMEDIR="/home/panos/Web Site"
    for file in $(find "$HOMEDIR" -type f)
    do
    if [ "$(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)")" -gt 30 ];
    then echo -e "File $file is $(dateDiff -d $(ls -lh "$file" | awk '{ print $6 }') "$(date +%F)") old\r" >> /home/panos/scripts/temp;
    fi
    done
    The dateDiff() function is defined earlier and the script works fine when I change the HOMEDIR variable to a path where there are no spaces in directory and file names. I have isolated the problem to the ls command, so a simpler code sample that also doesn't work correctly with path names with spaces is this:
    #!/bin/bash
    HOMEDIR="/home/panos/test dir"
    for file in $(find "$HOMEDIR" -type f)
    do
    ls -lh "$file"
    done
    TIA
    Last edited by panosk (2009-11-08 21:55:31)

    oops, brain fart. *flushes with embarrassment*
    -- Edit --
    BTW, for this kind of thing, I usually do something like:
    find "$HOMEDIR" -type f | while read file ; do something with "$file" ; done
    Or put those in an array:
    IFS=$'\n' ; files=($(find "$HOMEDIR" -type f)) ; unset IFS
    for file in "${files[@]}" ; do something with "$file" ; done
    The later method is useful when elements of "${files[@]}" will be used multiple times across the script.
    Last edited by lolilolicon (2009-11-09 08:13:07)

  • Sudo command in apple script? Encrypting apple script?

    Hi,
    1. I need a way to enter my root user password in applescript (when you run sudo in terminal you are prompted for a password, this is not so in apple script. So how do you tell apple script what the password is?)
    2. Can i encrypt my applescript with a password so that only i can open it?
    Thanks,
    Patrick.

    # 2 works great, #1 not so much... ive been trying
    tell application "Terminal"
         do shell script "su"
    end script
    any way i can auto enter my password following "do ....Su"?

  • Problem running sudo command in script

    Hello,
    I try to run this script.
    #!/bin/bash
    sudo /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin &
    The sudoers entry
    %users ALL= NOPASSWD: /bin/cat /dev/input/event1 >> /home/tom/.log/log.bin
    I get the following error!
    $ Passwort: sudo: pam_authenticate: Kommunikationsfehler
    Kommunikationsfehler = eng: communication error
    What's wrong with that?
    Thank you!
    clementis

    Sorry, for being not precise.
    I created the alias in .bashrc in my $home directory. In sudoers all users are allowed to key in this command without a passwort entry.
    I know how to autostart in xfce and so created an autostart entry but unfortunatly it doesn't work for my "special" command.
    What I did:
    1. I wrote a script (first post) and tried to autostart it in xfce. For that command I created an entry in sudoers in order to avoid enter root passwort. The script didn't start.
    Then...
    2. I created an autostart entry (deleted the first one - see point 1) and entered the whole command (cat .../event1 >> $home...) in the xfce autostart input window. The idea was to run the command directly and not through a script. But it didn't work.
    Therefore I tried to run alter the command to "bash cat .../event1 >> $home ...." Didn't work either.
    3. I also deleted the autostart entry no 2. and created the alias in .bashrc in my home directory. Now created a new autostart entry trying to start the alias. Didn't work.
    I also tried to set the Terminal option in the file $home/.config/autostart/log.desktop to "true".
    So it looked like this:
    [Desktop Entry]
    Encoding=UTF-8
    Version=0.9.4
    Type=Application
    Name=log
    Comment=event1
    Exec= sudo cat /dev/input/event1 >> /home/tom/.cblog/log.bin &
    StartupNotify=false
    Terminal=true
    Hidden=false
    The alias for example works well if I enter it in xterm.
    So, I don't know why it isn't working! :-(
    Thank you for any help
    Clementis

  • Bash script won't run "sudo reboot" under cron, but perfect manually

    Hi Archers,
    I've got a weird problem with a bash script I use to run pacman and mythtv updates once a week via cron which also reboots itself so that new mythtv and kernels packages become active. This script works likes a charm when I run it manually as user from the command line. But when cron runs it (also as user) it executes everything EXCEPT the last "sudo reboot" command at the end. Sudoers seems to be setup right as it works fine from the command line. I could run this particular script with cron as root but I'd prefer not to update under root with the --asroot command.
    Any ideas? It seems like the permissions running manually and with cron are different somehow.
    Many thanks!
    Last edited by wdirksen (2012-10-09 13:07:28)

    OK, I'm going to reconsider this based on all your advices, but I'm still curious about why the command doesn't execute with cron. Related to this, I also find it strange that some root commands work fine with sudo, while others only work within a true root environment
    DSpider wrote:Post your /etc/sudoers file.
    So here's my sudoers file:
    ## User privilege specification
    root ALL=(ALL) NOPASSWD: ALL
    mythtv ALL=(ALL) NOPASSWD: ALL
    . . . and this is the script:
    #!/bin/bash
    sudo pacman -Syyu --noconfirm
    /usr/share/mythtv/optimize_mythdb.pl
    /usr/share/mythtv/mythconverg_backup.pl --rotate 20
    mythtvname="mythtv-git-$(date +%Y%m%d)-1-x86_64.pkg.tar.xz"
    cd /home/mythtv/AUR/mythtv-git
    makepkg
    sudo pacman -U $mythtvname --noconfirm
    sudo reboot
    Anything stick out here?
    Last edited by wdirksen (2012-10-09 19:32:52)

  • Bash script: Loop command,

    Hi all,
    I need a bit of help looping a command on a bash script,
    please see below the command I need to loop:
    ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi
    So basically I record my screen for a period of 1 minutes and the process once done need to restart.
    I have search on how to loop the command but I must admit it seem rather complicated, so for the time being I added && at the end and paste the command a lot...
    Any help would be appreciated,
    Many thanks,
    Regards

    sweetthdevil wrote:ffmpeg -s 2720x1024 -r 25 -f x11grab -i :0.0 -acodec libmp3lame -ab 128k -vcodec mpeg4 -sameq -y -t 60 /media/z/.cam/screen/screen_`date +%F_%T`.avi
    I recommend using the FFmpeg commands shown here:
    How to do Proper Screencasts on Linux Using FFmpeg
    It's a well-written guide and the author, verb3k, keeps it up to date which is essential when working with FFmpeg.  Compared to your command the output will probably look better. The command from the guide will also probably be closer to your requested frame rate because the lossless output should be easier for the CPU to deal with and the command utilizes the -threads option.  Lastly, the -sameq option should not be used. The documentation is misleading and should read something like, "use same quantizer as source" instead of "use same video quality as source". Use of the same quantizer does not mean same quality, and this option especially should not be used when the source and output formats do not share the same quantizer scale.
    Last edited by DrZaius (2011-03-27 00:31:46)

  • Bash script run via cron not executing MYSQL command

    I have a bash script which is run from a cron,
    It is executing as I have it write to a log file which it does correctly.
    I am wanting the bash script to restore a mysqldump file.
    When I run the bash script manually the dump file gets loaded fine. But when I run it through the cron the mysql command appears to be ignored.
    The mysqldump file is 54MB and I have checked to make sure that MYSQL is included in the global users path in /etc/profile
    Does anyone know why this maybe??
    Here is the bash file
    #!/bin/bash
    date >> /home/user/crons/crons.log
    echo "Started loadbackup" >> /home/user/crons/crons.log
    cd /home/user
    dbuser=root
    dbpass=password
    dbname=databasename
    filename=backup
    mysql -hlocalhost -u"$dbuser" -p"$dbpass" "$dbname" < " >> /home/user/crons/crons.log
    My crontab looks like
    02 17 * * * /home/user/crons/loadbackup.sh
    Many thanks
    Richard

    Hi Richard,
    Have you tried redirecting the script output in the cron to see if an error is being reported?
    I.e.
    02 17 * * * /home/user/crons/loadbackup.sh > /tmp/loadbackup.log 2>&1

  • How to create script that run sudo-command, via automator?

    Hi
    I'd want to create script to automate one command I need quite often. I just can't get this to work.
    I'm not using english OS, but I think this is what I do. In automator I choose Utilities -> Run script
    Here's the script I try to run:
    sudo "/Library/Application Support/VMware Fusion/boot.sh --restart"
    I found some tip to do it like this:
    do shell script "sudo /Library/Application Support/VMware Fusion/boot.sh --restart password "pass" with administrator privileges
    Where pass is my admin password.
    This does not work, either.
    Could anybody help me on this?
    Thanks...
    Tomi Toivonen
    Message was edited by: Tomi

    This is not working. What's wrong?
    What's wrong is that the '--restart' is a parameter for boot.sh, and therefore needs to be included within the quotes.
    Additionally, the shell uses spaces to divide parameters, so the spaces in the command will make it appear as multiple commands - '/Library/Application', 'Support/VMware' and 'Fusion/boot.sh'. You need to escape them using a backslash:
    <pre class=command>do shell script "/Library/Application\ Support/VMware\ Fusion/boot.sh --restart" password "pass" with administrator privileges</pre>
    If it's outside of the quotes it would be interpreted as a parameter to 'do shell script' and it won't know what to do with that.

  • I want to disable 'Spotlight' for repairing my disk "Macintosh HD" , but somehow the command 'sudo mdutil -a -i off' does not work in 'Terminal'. I get result as ' bash: sudo: command not found' .I am using OS 10.10.  Please help.

    I want to disable 'Spotlight' for repairing my disk "Macintosh HD" , but somehow the command 'sudo mdutil -a -i off' does not work in 'Terminal'. I get result as ' bash: sudo: command not found' .I am using OS 10.10.  Please help.

    It appears that you may not have a properly installed OS X system.
    You must be connected to the Internet to reinstall OS X.
    In the menu bar, choose Apple menu > Restart. Once your Mac restarts (and the gray screen appears), hold down the Command (⌘) and R keys.
    Select “Disk Utility,” and then click Continue.
    Select your startup disk from the list on the left, and then Repair Disk.
    After disk is repaired, select Reinstall OS X, then click Continue.
    Follow the onscreen instructions. In the pane where you select a disk, select your current OS X disk

  • Can't run bash or sudo commands

    I have a Mac Pro with OS X 10.8.2 and also an older iMac running OS X 10.6.8. On neither Mac can I run any bash or sudo commands! I always get command not found.
    Both Macs have fresh installs of OS X, did I forget to install something? Is X11 needed? or Xcode?
    Thanks for any help.

    Back up all data.
    Select
    Shell ▹ New Command
    from the Terminal menu bar. Copy and paste the following line into the text box that opens:
    mkdir disabled_shell_files; mv .profile .bash* $_
    Your old shell initialization and history files will be saved in a directory with the indicated name at the top level of your home directory.

  • How to create script that run sudo-command?

    I often need to run command:
    sudo "/Library/Application Support/VMware Fusion/boot.sh" --restart
    This needs to be run as admin.
    Can anybody tell me how to create script that will login as admin and run that command in terminal?
    Or from where can I get help how to add commands to a script?
    Thanks
    Tomi

    Your best bet on getting a cogent answer is to post to the Unix forum under OS X Technologies.

  • -bash: sudo: command not found

         Hello all,
    I have had WAY too many problems with this laptop, and at this point in its miserable little life, I've decided to just wipe the hard drive and start fresh, not caring at all what happens to the files left on there. As previously stated in one of my earlier questions (That was, might I add, never fully answered.), this late 2008 MacBook (aluminum) has a problem where it does not boot up, and just endlessly shows the gray spinning pinwheel. Four months later, that just stops, and now when trying to boot up with my normal startup disk, it brings me right to the Recovery disk and tries to reinstall OS X. I tried, it failed 5 minutes in. So I tried to wipe the hard drive, and it says:  Disk Erase failed with the error: Couldn't unmount disk.   I looked it up and I saw that if I went into the Terminal and typed: sudo diskutil unmountDisk /dev/disk0 , it would unmount the disk. But whenever I type that, it says: -bash: sudo: command not found. I have no idea how to fix this, and I would really like to be able to use my laptop again without giving somebody my money to do it for me.
                                                 Thanks,
                                                      Luke

    Clean Install of Snow Leopard
    Be sure to make a backup first because the following procedure will erase
    the drive and everything on it.
         1. Boot the computer using the Snow Leopard Installer Disc or the Disc 1 that came
             with your computer.  Insert the disc into the optical drive and restart the computer.
             After the chime press and hold down the  "C" key.  Release the key when you see
             a small spinning gear appear below the dark gray Apple logo.
         2. After the installer loads select your language and click on the Continue
             button. When the menu bar appears select Disk Utility from the Utilities menu.
             After DU loads select the hard drive entry from the left side list (mfgr.'s ID and drive
             size.)  Click on the Partition tab in the DU main window.  Set the number of
             partitions to one (1) from the Partitions drop down menu, click on Options button
             and select GUID, click on OK, then set the format type to MacOS Extended
             (Journaled, if supported), then click on the Apply button.
         3. When the formatting has completed quit DU and return to the installer.  Proceed
             with the OS X installation and follow the directions included with the installer.
         4. When the installation has completed your computer will Restart into the Setup
             Assistant. After you finish Setup Assistant will complete the installation after which
             you will be running a fresh install of OS X.  You can now begin the update process
             by opening Software Update and installing all recommended updates to bring your
             installation current.
    Download and install Mac OS X 10.6.8 Update Combo v1.1. You may then open App Store, click on the Purchases icon in the toolbar, and re-download any OS X upgrade you purchased except Mavericks. Since Yosemite has been released the App Store may not let you re-download Mavericks, but it will let you download Yosemite.

  • [solved] Running a command in background (bash script)

    Salut,
    as netcfg2 does not work with my wireless connection, I have to set up the connection manually. For not having to type in the commands every time, I created a bash script.
    #!/bin/bash
    iwconfig wlan0 mode managed essid mynetwork channel 6
    ifconfig wlan0 up
    wpa_supplicant -D wext -i wlan0 -c /etc/wpa_supplicant.conf -dddd &
    dhcpd wlan0
    This works fine till the wpa_supplicant line. wpa_supplicant is not started in the background (as I thought, the ampersand at the end of the line would.
    So how can I get wpa_supplicant run in the background?
    Thanks in advance,
    Stefan
    Last edited by vbtricks (2008-05-11 09:13:36)

    Ramses de Norre wrote:How do you know it isn't? What exactly does happen?
    The script does not return to the user-prompt. Is an ampersand at the end of the line the correct solution, or are you unsure yourself?
    bender02 wrote:On thing is that even if it starts, it does take it a couple of seconds to connect, so it's probably not very good to run dhcpcd right after wpa_supplicant. Another thing is that you probably have a typo up there, shouldn't it be 'dhcpcd' instead of 'dhcpd'?
    Well, as the wpa_supplication command is not really run in the background the script did never execute the dhcpcd command. After having solved the above, correcting the spell-mistake will be a smaller problem. Even calling the dhcpcd command myself would be no unworkable way, the open root-shell (as I have to use another as the one calling the script is blocked) is a far greater problem...

  • Terminal/bash stalls at password-prompt after sudo-command

    hi,
    under 10.5.2 Terminal lets me type or paste a sudo-command, but then, asking for my root-password, does not react to any inout from keyboard or via paste. What can that be?

    It is normal for nothing to appear on the screen while the password is being typed. Press Enter when you've finished entering it.
    (30698)

  • What do you think of my Bash Script? What about the error checking?

    Well what do you think of this Bash script
    It works
    I gave it some problems (i.e. unpluged the ethernet, messed up the URL's, uninstaled some programs...) to see if would report errors and stop or just keep going... But it did
    I just kind of thought up a way to do some error checking with the commands that I know.....
    What is a better way to do error checking?
    What do you think I should add/Do to this script?
    #!/bin/bash
    # Shell script to make a USB Tumb Drive for Flashing BIOS on a Lenovo Ideapad Y510.
    # This script needs to be owned and run as ROOT with the "sudo command"
    # i.e. sudo usbbiosflasher
    # If you have anyideas send me a PM on ubuntufourms.org my user name is HunterThomson
    # Name/Rename this script usbbiosflasher and save it to the ~/home directory.
    # Then run the command- chown root:root usbbiosflasher
    # Then run the command- chmod 755 usbbiosflasher
    # Then copy the script to the directory /usr/bin.
    # Run this comand to do that- sudo cp ~/usbbiosflasher /usr/bin
    # You also must have the program "mbr" installed
    # You can install the mbr program by running this comand in the shell on Ubuntu
    # sudo apt-get install mbr
    # In Arch Linux you have to get it from Aur
    # First you will need to know a few things...
    # You will also need to know the Mount Point i.e. /media/disk and the /dev path i.e. /dev/sdb1.
    # You can find these by using the df -T comand.
    # Run df -T in the shell. Then plug in the USB Thumb Drive and run the df -T comand agin.
    # The new listing is the USB Thumb Dirve.
    # Also check to make sure the File System tipe is vFAT or FAT16 or FAT32.
    # If it is not use gparted to format it to FAT32.
    # I am farly certen that all USB Thumb drives come formated with FAT file system out of the BOX.
    # You may want to fromat it anyway just to make sure.
    echo "Interactive Shell Script to Make a USB Thumb Drive \for Flashing BIOS On a Lenovo Ideapad Y510"
    echo ""
    echo "You will need to have the program mbr installed"
    echo "If you are on Ubuntu Linux you can retreve it form the repositories"
    echo "If you are on Arch Linux you will need to get it from the Aur repository"
    echo "Open anuther shell and \do that now..."
    echo ""
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you have mbr installed... yes or no?"
    read AN1
    echo ""
    printf "You answered... $AN1 I have installed mbr. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN1" == "no" ]
    then
    echo "Install mbr now. Then run this script agin"
    exit
    else
    echo "contunuing script"
    fi
    echo ""
    # The next comand will make a directory to put needed files into. Note this file and everything init will be owned by root.
    mkdir ~/usbbiosfiles && check1="yes"
    if [ "$check1" = "yes" ]
    then
    echo "Made directory usbbiosfiles... OK"
    else
    echo "Could not \make directory usbbiosfiles"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    exit
    fi
    # The next two comands will get the FreeDOS file and the .ROM file.
    cd ~/usbbiosfiles && checka="yes"
    if [ "$checka" = "yes" ]
    then
    echo "Changing to the usbbiosfiles directory... OK"
    else
    echo "Could not Change to the usbbiosfiles directory"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    wget "http://www.fdos.org/bootdisks/autogen/FDOEM.144.gz" && check2="yes"
    if [ "$check2" = "yes" ]
    then
    echo "Download of FreeDOS... OK"
    else
    echo "Could not Download FreeDOS"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    wget "http://ubuntuforums.org/attachment.php?attachmentid=78460&d=1216648756" && check3="yes"
    if [ "$check3" = "yes" ]
    then
    echo "Download of the BIOS.ROM \file... OK"
    else
    echo "Could not Downlad the BIOS.ROM \file"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    # The next comand will name the .ROM file to the right name.
    mv ~/usbbiosfiles/attachment.php?attachmentid=78460\&d=1216648756 ~/usbbiosfiles/06CN29WW.bios.update.tar.bz2 && check4="yes"
    if [ "$check4" = "yes" ]
    then
    echo "Renameing of the BIOS.ROM \file... OK"
    else
    echo "Could not rename the BIOS.ROM \file"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    echo ""
    # The next two comands set the variables. DEVX for the path i.e. /dev/xxx and MOUNTX for the mount point i.e. /media/xxx
    verify="n"
    while [ "$verify" != y ]
    do
    echo "You will need to know the Mount Point and the dev Path. You will also need to \make sure the File System \type is vFAT, FAT16 or FAT32."
    echo ""
    echo "With the USB Thumb Drive unpluged, Open another shell and run the comand df -T Then plug \in the USB Thumb Drive and run the comand df -T one \more time. The new device listed is the USB Thumb Drive. Note the Mount Point and The dev Path and the File system Type i.e. vFAT... If the File System \type is not vFAT, FAT16 or FAT32 you will need to fromat it with gparted. You may want to format the USB Thumb Drive anyway just to \make sure. In any \case delete all files and directorys on the USB drive before you go any ferther with this program."
    echo ""
    printf "Enter the dev path the USB Thumb Drive is at?"
    read DEVX
    echo ""
    echo "Are you sure $DEVX is the dev path of the USB Thumb Drive... y or n?"
    read verify
    done
    echo ""
    verify="n"
    while [ "$verify" != y ]
    do
    printf "What is the Mount Point of the USB Thumb Drive?"
    read MOUNTX
    echo ""
    echo "Are you sure $MOUNTX is the Mount Point of the USB Drive... y or n?"
    read verify
    done
    echo ""
    install-mbr --enable A1 --partition 1 --force --timeout 0 $DEVX && check5="yes"
    if [ "$check5" = "yes" ]
    then
    echo "Installing MBR on USB Thumb Dirve... OK"
    else
    echo "Could not install MBR on USB Thumb Drive"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    tar xjf ~/usbbiosfiles/*.tar.bz2 && check7="yes"
    if [ "$check7" = "yes" ]
    then
    echo "Unpacking BIOS.ROM file... OK"
    else
    echo "Could not unpack BIOS.ROM file"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    gunzip ~/usbbiosfiles/FDOEM.144.gz && check8="yes"
    if [ "$check8" = "yes" ]
    then
    echo "Unpacking FreeDOS files... OK"
    else
    echo "Could not unpack FreeDOS files"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    mkdir ~/usbbiosfiles/fdoem144 && check9="yes"
    if [ "$check9" = "yes" ]
    then
    echo "Made directory fdoem144 in direcoty usbbiosfiles... OK"
    echo ""
    echo "Going to \sleep \for 5secs"
    else
    echo "Could not make directory fdoem144 in usbbiosfiles directory"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    modprobe loop && sleep 5 && check0="yes"
    if [ "$check0" = "yes" ]
    then
    echo "Modprobeing loop... OK"
    else
    echo "Could not \modprobe loop"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    mount -o loop ~/usbbiosfiles/FDOEM.144 ~/usbbiosfiles/fdoem144 && check10="yes"
    if [ "$check10" = "yes" ]
    then
    echo "Mounting FreeDOS on the fdoem144 directory... OK"
    else
    echo "Could not \mount FreeDOS on the fdoem144 directory"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    cp ~/usbbiosfiles/fdoem144/* $MOUNTX && check11="yes"
    if [ "$check11" = "yes" ]
    then
    echo "Copying FreeDOS files to $MOUNTX... OK"
    else
    echo "Could not copy FreeDOS files to $MOUNTX"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    cp ~/usbbiosfiles/*.ROM $MOUNTX && check12="yes"
    if [ "$check12" = "yes" ]
    then
    echo "Copying BIOS.ROM files to $MOUNTX... OK"
    else
    echo "Could not copy BIOS.ROM files to $MOUNTX"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    sync && check13="yes"
    if [ "$check13" = "yes" ]
    then
    echo "Runing the syncing command... OK"
    else
    echo "Could not run the syncing command"
    echo "look above \for \info"
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this scrip agin"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    rm -r ~/usbbiosfiles
    exit
    fi
    umount ~/usbbiosfiles/fdoem144 && check14="yes"
    if [ "$check14" = "yes" ]
    then
    echo "Unmounting of FreeDOS... OK"
    else
    echo "Could not unmount FreeDOS"
    echo "Look above for errors or problems reported and fix the problem"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this script agin"
    rm -r ~/usbbiosfiles
    exit
    fi
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you see any errors... yes or no?"
    read AN2
    echo ""
    printf "You answered... $AN2 to errors. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN2" == "yes" ]
    then
    echo "User Repoted... Error"
    echo "Look above for errors or problems reported and fix the problem"
    echo ""
    echo "removeing directory usbbiosfiles..."
    echo ""
    echo "Reformat the USB Stick to FAT32 with gparted"
    echo "Fix the problem and run this script agin"
    rm -r ~/usbbiosfiles
    exit
    else
    echo "Success"
    echo "I did a lot of error checking too and didnt find anything"
    echo ""
    echo "Go get a pen and paper to write down these instructions"
    printf "Then hit the Enter to continue"
    read WAIT
    echo ""
    echo "Now leave the USB Thumb Drive pluged into your computer and Reboot. When the Lenovo Logo POST screen appears hit F2 to enter the CMOS setup utility. Go over to BOOT tab and go down to HardDrive \(Not Boot Order) \then \select the USB Thumb Drive as the 1st hard drve. Then F10 and yes to save changes. Your compter will reboot agin. Then when the Lenovo Logo POST Screen appers on reboot hit F4 to enter the BIOS FLASHING program. The USB Thumb Drive will be seen as the C drive \in the list on the Left, Select it. Then \select the .ROM \file \in the list on the Right and start the BIOS FLASH. \(NOTE Your hart may stop beating... This is normal) Pray to any God you know of and your computer should restart just like normal. Hit F2 and the BIOS will now stay it is 06CN29WW. You will need to \set the boot order to the way you like it and other things \if you need to because they have been changed to the default."
    fi
    echo ""
    echo "End of script"
    Last edited by hunterthomson (2008-08-10 11:17:47)

    Personally.....  (this is just how I would have written it - if it works, then it's good enough for me though )
    I would change this whole block:
    verify="n"
    while [ "$verify" != y ]
    do
    printf "Do you have mbr installed... yes or no?"
    read AN1
    echo ""
    printf "You answered... $AN1 I have installed mbr. Is this correct... y or n?"
    read verify
    done
    echo ""
    if [ "$AN1" == "no" ]
    then
    echo "Install mbr now. Then run this script agin"
    exit
    else
    echo "contunuing script"
    fi
    To this much shorter code:
    MBR='/usr/bin/install-mbr' # Or where ever you expect it to be
    if [ ! -x $MBR ] ; then
    echo "mbr doesn't appear to be installed."
    echo "If it is installed, check it's location, make sure it's executable and then make sure the MBR variable in this script is correct"
    exit 1
    fi
    I wouldn't have used the checkXX variables for each stage:
    mkdir ~/usbbiosfiles
    if [ $? != 0 ] ; then
    #failed
    echo "Could not \make directory usbbiosfiles"
    echo "look above \for \info"
    echo "Fix the problem and run this scrip agin"
    exit 1
    else
    echo "Made directory usbbiosfiles... OK"
    fi
    There is an issue with the way you do your verifications - the user can never get out unless they answer 'y' or hit CTRL+C. Something like this gives them options:
    verify="n"
    while [ "$verify" != "y" && "$verify" != "n" ]; do
    echo "You need to answer 'y'es or 'n'o"
    read verify
    echo $verify | tr "[:upper:]" "[:lower:]" # This converts the answer to lowercase so replies entered in upper case will still work
    done
    if [ $verify != 'y' ] ; then
    exit 1
    fi
    One last thing I try to do in scripts... Declare all your binaries as variables at the start of the program, then execute the binary program by using the variable. For example:
    # Binaries
    TAR='/bin/tar'
    CP='/bin/cp'
    CHMOD='/bin/chmod'
    # Execute tar and chmod the created file
    $TAR cvzf /tmp/tarfile.tar.gz /etc/*.conf
    $CHMOD 400 /etc/*.conf
    This way, it's easy to change the path in future without having to hunt through the script if the paths change, and it also ensures you're calling the programs using the full paths to make sure you're not executing some strange variant or alias that someone has setup. If I use `chmod` 30 times in a script, and the path changes in the future or on a different system (`chmod` is a bad example cause it's highly unlikely to change, but you know what I mean), then all you need to do is update the variable at the start of the script, and it all works again without having to script-hunt and change it 30 times.

Maybe you are looking for