Shell Script Question: Detect/Wait for USB Stick to be Ready
RobertKaucher
Member Posts: 4,299 ■■■■■■■■■■
in Off-Topic
I have a POS Linux box, some older version of Open SUSE, and I have a script that unmounts the USB thumb drive, formats it, and then waits for the device to become ready again before it runs a script that does a copy/MD5 checksum verification on the source and destination file to ensure the copy was valid. The problem is that on one box the USB thumb drive does not become ready after the format in a consistent way. I takes anywhere from 1 to 2+ minutes before I can access the drive via /media/LABELNAME.
The direct path is /dev/sdb but, of course, I cannot access it directly via this path to copy the files. Here is my shell script as it stands:
Any suggestions?
The direct path is /dev/sdb but, of course, I cannot access it directly via this path to copy the files. Here is my shell script as it stands:
#!/bin/bash set -e echo "Starting LABELNAME.\n\nUnmounting /dev/sdb/" umount /dev/sdb echo "Formatting /dev/sdb/" mkfs.vfat -I -F32 -n "LABELNAME" /dev/sdb echo "Waiting on remount..." sleep 30 echo "Format complete. Running make master." perl /home/labelname_master.20120830.pl
Any suggestions?
Comments
-
UnixGuy Mod Posts: 4,570 ModSo for some reason on one of the boxes and format (mkfs) command takes more time? The reason could be anything, the box might be slow or the system is busy doing something else.
How about giving it more time by increasing the "sleep 30" from 30 seconds to say, 90 seconds (sleep 90) ? -
dontstop Member Posts: 579 ■■■■□□□□□□
#!/bin/bash set -e echo "Starting LABELNAME.\n\nUnmounting /dev/sdb/" umount /dev/sdb echo "Formatting /dev/sdb/" mkfs.vfat -I -F32 -n "LABELNAME" /dev/sdb echo "Waiting on remount..." sleep 30 echo "Format complete. Running make master." perl /home/labelname_master.20120830.pl
Any suggestions?
S_DIR is the Directory that your drive mounts as i.e. /media/LABELNAME
This will loop until it finds the mounted drive file.#!/bin/bash S_DIR="/tmp/hereiam.file" while [ `stat ${S_DIR} 2>/dev/null 1>&2; echo $?` -ne 0 ] do sleep 1 echo "Not found yet :)" done