I have Linux image that on boot, needs to execute a script that will be located on a plugged in thumbdrive. Here is what I have.
mkdir /mnt/usb mount /dev/sda1 /mnt/usb cd /mnt/usb/DMS cp script.sh / chmod +x /script.sh /bin/sh /script.sh
This script is added late in the sysvinit scripts. It works with most drives, however, some drives take a while to get recognized. That means my script will fail, because
/dev/sda1 isn't available yet.
How do I modify this shell script to perform a while/wait on the device, with a timeout if none is ever found.
counter = 1 while /dev/sda1 not present sleep 100 counter++ if counter is 50 exit # no drive ever found endif endwhile # do stuff with plugged in drive, mount it, whatever
How do I perform something like this in a shell script?