automount and umount script
Posted 08-16-2012 at 12:30 PM by ted_chou12
This is a sciprt that automounts and unmounts usb devices, because I realized my system does not consistently automount drives, and sometimes gets mounted incorreclty:
calling the script directly mounts all drive and by:
unmounts ALL drives, unfortunately, I haven't enable the luxury of unmounting one at a time. I am glad to accept improvements.
Ted
Code:
#mounts start with f tbmounted=(f g h i j k l m n o p q r s t u v w x y z) for each in "/dev/sd"* ; do mname=${each##*/} for alphabet in ${tbmounted[@]} ; do if [ "$mname" == "sd$alphabet" ] ; then mounts=$(mount | grep "$mname") if [ -z "$mounts" ] ; then i=1 if [ ! -e "/dev/sd$alphabet$i" ] ; then if [ ! -d "/mnt/sd$alphabet" ] ; then mkdir "/mnt/sd$alphabet" fi mount "/dev/sd$alphabet" "/mnt/sd$alphabet" else while (( $i < 10 )) ; do if [ ! -e "/dev/sd$alphabet$i" ] ; then if [ ! -d "/mnt/sd$alphabet" ] ; then mkdir "/mnt/sd$alphabet" fi mount "/dev/sd$alphabet$((i-1))" "/mnt/sd$alphabet" ; break fi i=$((i+1)) done fi fi fi done done if [ ! -z "$1" ] ; then for each in ${tbmounted[@]} ; do mounts=$(mount | grep "sd$each") if [ ! -z "$mounts" ] ; then umount "/mnt/sd$each" rm -r "/mnt/sd$each" fi done fi
Code:
./automount.sh kill
Ted
Total Comments 0