Auto-mounting samba shares at startup
I'm in an office where samba shares are always different depending on the time, for instance at this time, jack and josh are connected, but jane is out of the office. Later, jane is here but jack has gone. You get the picture.
At the moment, I mount my samba shares manually from the terminal, because I use Gnome. I'd like a script to run each minute with a Cron job to check available samba shares on the network, and to mount or unmount them silently, depending if the share is available or not. Does some one have a script like this to create dynamically mount points under /mnt ? How could we do it? Thanks ;) |
oh no no no you don't want to do that. you want to use autofs, which does exactly what you want... mounting on demand. centos does contain a script to mount smb shares, but afaik it's actually horribly horribly borked, unliek the nfs one which always works fine. what i'd suggest is just defining a few specific entries for autofs, rather than the cleverer approach the defective scripts in /etc/ try to use.
|
Thanks Chris, how do I get started to set that up?
|
You need an auto.master and auto.<service_name> file, usually in /etc/. Both files should be executaable.
Here's mine, from my Fedora system: Code:
$ cat /etc/auto.master | grep -v ^# Notice that the connection script also looks for a "credentials" file containing the remote login information. Since my systems are open to everyone on the local net, I put them (the credentials) in /etc, but a better solution would be to look in, say, ~/.smbpasswrd for the user's credentials. The autofs mounts the shares when they are first needed. The timeout=0 setting, above, keeps them mounted "forever," but other timeouts can be specified (in minutes). Here's a script that could be called from a user's login to connect for them : Code:
$ cat Scripts/MountSmb |
yeah, it's the awk statements in the script there that have always been totally screwed up. as above, if that is the case, i would strongly suggest just adding manual shares yourself, instead of this automated approach.
|
Quote:
<edit> As an alternative to the script, run it (the script) by hand, capture the output to a file, and write a bash script to cat the file when called. Then you can "tweak" the file to your hearts content before it's used, and, of course, have a different file for each user. The point in the script is to mount all shares available from $key, so "tweaking" might be desirable in some cases. The point of the script is just to get the automount information into the correct format. </edit> |
All times are GMT -5. The time now is 05:08 AM. |