LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Blogs > ted_chou12
User Name
Password

Notices

Rate this Entry

mount scripts

Posted 08-27-2012 at 02:39 PM by ted_chou12

These are scripts that searches for local drives and network shares (cifs). I am putting this up for whoever looking for a ready made script also for my future references:
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 "$each")
				if [ -z "$mounts" ] ; then
					i=1
					if [ ! -e "/dev/$mname$i" ] ; then
						if [ ! -d "/mnt/$mname" ] ; then
							mkdir "/mnt/$mname"
						fi
						mount -o utf8 "/dev/$mname" "/mnt/$mname"
						echo "USB device $mname is mounted at \"/mnt/$mname\"!"
					else
						while (( $i < 10 )) ; do
							if [ ! -e "/dev/$mname$i" ] ; then
							if [ ! -d "/mnt/$mname" ] ; then
								mkdir "/mnt/$mname"
							fi
							mount -o utf8 "/dev/$mname$((i-1))" "/mnt/$mname"
							echo "USB device $mname is mounted at \"/mnt/$mname\"!" ; break
							fi
							i=$((i+1))
						done
					fi
					
				fi
		fi
	done
done

if [ -e "/dev/sr0" ] ; then
	if [ -z "$1" ] ; then
		if [ -z "$(mount | grep "/dev/sr0")" ] ; then
			mount -o ro "/dev/sr0" "/mnt/cdrom"
			echo "CD-rom is mounted at \"/mnt/cdrom\"!"
		fi
	else
		umount "/mnt/cdrom"
	fi
fi


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:
output="$(nmblookup -S workgroup)"
IFS=" "
outputs=($output)
for each in ${outputs[@]} ; do
	if [ "${each:0:10}" == "192.168.1." ] && [  "${each:0:13}" != "192.168.1.255" ] ; then
		IFS="
		"
		parts=($each) ; ip="${parts[0]}" ; netbios="${parts[1]}"
		if [ ! -e "/mnt/share/$netbios" ] ; then
			mkdir "/mnt/share/$netbios"
		fi
		output1="$(smbclient -N -L //$ip -g)"
		IFS="
"
		dirs=($output1)
		for each1 in ${dirs[@]} ; do
			if [ "${each1:0:4}" == "Disk" ] ; then
				IFS="|"
				dir=($each1)
				if [ ! -e "/mnt/share/$netbios/${dir[1]}" ] ; then
					mkdir "/mnt/share/$netbios/${dir[1]}"
				fi
				if [ -z "$1" ] ; then
					echo -n "mounting //$netbios/${dir[1]}......................"
					fb=$(mount -t cifs -o username=ted,password= //"$ip"/"${dir[1]}" /mnt/share/"$netbios"/"${dir[1]}" 2>&1 >/dev/null)
					if [ -z "$fb" ] ; then
						echo "		OK"
					else
						echo "		Failed"
					fi
				else
					echo -n "umounting /mnt/share/$netbios/${dir[1]}..................."
					fb=$(umount "/mnt/share/$netbios/${dir[1]}" 2>&1 >/dev/null)
					if [ -z "$fb" ] ; then
						echo "		OK"
					else
						echo "		Failed"
					fi
				fi
				i=$((i+1))
			fi
		done
	fi
done
Posted in Uncategorized
Views 423 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration