|
Re: Auto mount smb shares
This is a script that I wrote using mount.cifs from the smbclient package in samba. It won't work with versions of samba distributed after Fedora 12. If you have an older copy of the distro then you can extract mount.cifs and umount.cifs from it and copy to /usr/local/sbin/ . The binaries are arch version independent, as I've been copying them between distro upgrades. So here's my code:
# sharemount
#!/bin/bash
# sharemount <sharename 1> <sharename 2>
# This script will test for <server> on the network and then mount shares or
# issue an error message
share="$@"
if ping -w 2 -c 1 <server> && smbclient -NL <server>; then
echo "<server> is present"
for share in "$@" ; do
mkdir ~/$share
/usr/local/sbin/mount.cifs //<server>/$share ~/$share -o credentials=~/.samba/.$USERNAME
done
else
echo "The server <server> could not be reached. Is it on?"
fi
##################################### end ################################
I also wrote a logout script to delete the empty mount points when done:
# logoutsmb
#!/bin/bash
# logout <share 1> <share 2>
# this program un-mounts network shares and then calls gnome-session-save
# with the --logout option
share="$@"
for share in "$@" ; do
if [ -d ~/$share ]; then
/usr/local/sbin/umount.cifs /home/$USERNAME/$share
wait=2
rmdir /home/$USERNAME/$share
wait=1
fi
done
/usr/bin/gnome-session-save --logout
##################################### end ######################
This script will log you out when executed, if you don't want that then remove the last line.
You need to substitute the name or IP address of your server for <server> in the sharemount script.
__________________
jbkt23
Last edited by jbkt23; 9th November 2010 at 02:26 AM.
Reason: Clarification
|