• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Check Device with Script File

saptech

Android Expert
Is there a way for a script file to check if the usb hard drive is connected and if it is, continue, if not, pause with message asking user to check the connection or power?

How would I go about having the script check for the device?

Thnx.
 
Well, I'm wanting to write a script to do a backup of my system. I'm backing up to an external hard drive. This is what I have so far. Keep in mind, I'm not any good at writing scripts.

while true
do
# (1) prompt user, and read command line argument
read -p "Is this a Backup, Restore or Cancel:? " answer

# (2) handle the input we were given
case $answer in
[bB]* ) fsarchiver backup command goes here
echo "Okay, Backup is done!."
break;;

else
case $answer in
[rR]* ) fsarchiver restore command goes here
echo "Okay, Restore is done!."
break;;

[cC]* ) exit;;

* ) echo "Dude, just enter B, R or C, please.";;
esac
done
 
EVERYTHING is possible with *nix, so, yes, it's possible to check for the drive's existence before proceeding. However, I'm so far out of the loop that I have no idea [right now] how to check for a USB drive's presence. I mean elegantly. There's an easy workaround, which is to simply place a file on it and then check for its existence.

If someone else doesn't pop in with a way to do it elegantly, I'll do some experimenting and see what I can come up with.
 
Here's a start (assuming that you will always back up to the same disk)

Code:
ls /dev/disk/by-uuid/$UUID | tail -c +19

where $UUID is the uuid of the drive you are using. The result of the tail command could then be piped to another command.
 
Thanks for that. I'll keep these ideas in mind. Yes for now anyway, it will be the same ext. hd. And using an existing file on the ddrive is a good ideal also, Moody.

I'm just playing around with writing simple scripts to get better familar with them. I will work on it during the weekends.

Thnx. again.
 
Back
Top Bottom