LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Re-mount CIFS share only if not mounted? (https://www.linuxquestions.org/questions/linux-networking-3/re-mount-cifs-share-only-if-not-mounted-4175629075/)

NDev 05-05-2018 05:17 AM

Re-mount CIFS share only if not mounted?
 
Hi,

I have an Ubuntu 16 system that always needs to have a handful of Samba shares mounted.

I put "mount -a" into a cronjob, just in case there was a network problem, and those samba-mounts have been lost/umounted for some network-reason.

But now i noticed, when i excecute just "mount" without any arguments, that those shares are mounted like a hundred times. The output is huge.
Cause everytime "mount -a" is running via cron, its generating new lines there. Making it look as if those shares are mounted plenty of the times in the same way.
It does not seem to make a problem right now. But i could imagine that some buffer or limit will be reached some day with this. And it does not appear to be very clean.

Is there a proper way to do this?
Of course i could do an umount -a , and then mount -a . But this would break connection to those samba shares of course.

Is there no way to re-mount them, just if they are currently NOT mounted?

Regards,
ND

michaelk 05-05-2018 07:50 AM

You can check to see if the share is still mounted using the mountpoint command although I do not think it would help your network problems since the mount point might be "stale"

Using autofs or systemd automount might help. The shares are automatically unmounted after an idle timeout period and automatically mounted when accessed.

How often do you have network problems?

voleg 05-07-2018 01:38 AM

You should use autofs for CIFS mounts. Linux cannot easy remount CIFS share if windows rebooted and new session should be established.
Here is mine example for SuSE, however it should be exactly the same for you.
Automount CIFS on SLE11SP4

NDev 05-07-2018 03:28 PM

Ok, Thanks Michaelk and Voleg.
Im gonna give Autofs a try in the weekend.

@voleg: Your Example is well explained, and seems simple / easy to reproduce. I will use it when i try it.

michaelk 05-07-2018 04:02 PM

While the configuration files will be the same, installing and running autofs are a bit different with Ubuntu.

https://www.itzgeek.com/how-tos/linu...ntu-14-04.html

https://help.ubuntu.com/community/Autofs


All times are GMT -5. The time now is 06:30 PM.