Best way to mount remote shares automatically?
When I boot my laptop, my remote shares are mounted automatically by fstab.
But I rarely reboot my laptop. When I leave my local network area, shares are unmounted automatically. When I come back, I reconnect using a manual mount command. That works fine but I would like to know if there is a way to automatically reconnect the shares? Thanks Using Mageia3 with KDE |
can your network manager run a script upon connection to a network? Might be an option (I think wicd has this sort of feature).
|
pam_mount can be what you looking for :)
|
I'm very new to scripting but maybe a script that checks if the shares are there or not, if they are it mounts them, if not then it just exits. Put it on roots crontab every... 5 minutes?
|
First function I've made with a bit of googling to find the command to use.
Code:
#!/bin/bash |
Variation on a theme
Thanks Tadaen
mountpoint is a good avenue. Your solution works fine but it may fill your log with useless messages when you're not connected to server. I propose: Code:
SRV=tatata Code:
SRV=tatata |
I am very new to scripting. I like your idea better. As far as the log is concerned I could probably alter mine to run once with a while statement and just have it sleep 300 or so. Shouldn't fill the log up then I would imagine. I don't know enough though. I will test it. Yours is more elegant though from what little I do know.
|
Code:
#!/bin/bash *EDIT* Actually looking at how easy this was to set up as a while loop I will be changing some of my other scripts so that they also don't load the log with nonsense as I have 2 that run every 30 mins and 1 that runs every 10 to backup my ramdisk. |
Better still. Will run every 5 minutes. This requires the shares to be in the /etc/fstab.
Code:
#!/bin/bash |
Hi Tadaen
OK! Let's suppose you're out of the office and your server is not reachable. Every 5 minutes, you will attempt a mount and an error message will be logged. That's what I meant by "fill with useless message". Would be better to check for reachabibity before you call mount. You can do it with "ping -c 1". Next, suppose you have 2 servers, possibly on two different networks (or in 2 offices). One being reachable does not mean the other is. So your "mount -a" will generate useless messages for the unreachable server. Conclusions - do a ping before you attempt mounting of remote ressources. Only attempt mounting if server is reachable. - do it "per server" and do not use "mount -a" As an exercise you may try to write a function with 2 arguments (server_address and mount_point). |
i got it backwards you are correct. looking into it now.
*EDIT* Ok for samba, and mounting as user not root. Lines like this in the /etc/fstab. I'm guessing this could be modified for just a certain user so no one else can mount them but I'm done googling for now. Code:
//ServerIP/Share /mount/point cifs credentials=/home/youruser/creds,noauto,user 0 0 Code:
#!/bin/bash *EDIT* Thank you for the suggestions and somewhat challenge. I am trying to learn as fast as I can. |
Variation on a theme
Hi!
when a share is declared in /etc/fstab then mount can be called either with the mount_point or the share_path This enable you to reduce the number of args to 2 Code:
# mymount() Also, I did put the mountpoint call in front of ping because mountpoint is a lighter and faster system call. But it would also work the other way around. |
And now I think I understand positional parameters. I learn by example. Thank you much.
Also didn't know until now that you could mount an /etc/fstab entry by the mountpoint and not the device / location you are mounting from. |
All times are GMT -5. The time now is 09:35 PM. |