LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > ted_chou12
User Name
Password

Notices


Rate this Entry

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:
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
calling the script directly mounts all drive and by:
Code:
./automount.sh kill
unmounts ALL drives, unfortunately, I haven't enable the luxury of unmounting one at a time. I am glad to accept improvements.
Ted
Posted in Uncategorized
Views 714 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 07:59 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration