Auto mounting usb device on linux server
Jim Kuzdrall
gnhlug at intrel.com
Wed May 10 00:03:00 EDT 2006
On Tuesday 09 May 2006 09:52 pm, Cole Tuininga wrote:
> device. Extra points if I can also kick off a script once the drive
> is mounted.
This is what I do to find the auto-mounted usb drive. From your
log, it appears that all the same information is there. You can have
the whole backup script if you are interested.
Jim Kuzdrall
# 8. Find flash, sd?1, using /proc information-----------------
set -- $( ls /proc/scsi/usb-storage)
cnt=0
while [ "$1" != "" ] ; do
cat /proc/scsi/usb-storage/$1 | grep $SER_NR &> /dev/null
# zero means 'found'
if [ $? -eq 0 ] ; then
FLASH_LET=${T[cnt]}
FLASH_DEV=/dev/sd${FLASH_LET}1
echo "Flash found at ${FLASH_DEV}" >> $LOG_FN
break
fi
let "cnt = cnt + 1"
shift
done
if [ "$1" = "" ] ; then
echo "Finished with error; Flash disk not found" | tee -a $LOG_FN
exit 5
fi
# 9. Make flash storage mount directory, if needed -----------------
# USB usually has the device mounted somewhere; if so, find out where
TMP=$(mount | grep $FLASH_DEV )
if [ "$TMP" = "" ] ; then
if [ ! -d $FLASH_MNT ] ; then
mkdir --parents $FLASH_MNT
fi
mount $FLASH_DEV $FLASH_MNT
else
TMP=${TMP#*on\ }
FLASH_MNT=${TMP%\ type*}
FLASH_DIR=$FLASH_MNT/"aaa_bkup"
fi
if [ ! -d $FLASH_DIR ] ; then
mkdir --parents $FLASH_DIR
fi
More information about the gnhlug-discuss
mailing list