Linux - Laptop and NetbookHaving a problem installing or configuring Linux on your laptop? Need help running Linux on your netbook? This forum is for you. This forum is for any topics relating to Linux and either traditional laptops or netbooks (such as the Asus EEE PC, Everex CloudBook or MSI Wind).
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
#Check if mounted & mount if not from /etc/fstab
#Tadaen Sylvermane
#Created 2014/1/21
if mountpoint -q /path/to/mount ; then
exit 1
else
mount -a
exit 1
fi
Now that I've made this I will likely use it in the near future here and just have it run as a root crontab every couple mins.
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
MNT=mount_point
if mountpoint -q $MNT; then
exit 1; # already mounted
elif ping -c 1 $SRV >/dev/null; then
mount $MNT # we assume it is defined in fstab
exit 2; # mount
else
exit 3; # server unreachable
fi
or, if you prefer brevity:
Code:
SRV=tatata
MNT=mount_point
if ! mountpoint -q $MNT && ping -c 1 $SRV>/dev/null; then mount $MNT; fi
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.
#!/bin/bash
#Check if mounted & mount if not from /etc/fstab
#Add to boot list as root.
#Tadaen Sylvermane
#Created 2014/1/25
while true; do
if mountpoint -q /path/to/mountpoint ; then
sleep 60
else
mount -a
sleep 60
fi
done
This one works and doesn't fill the log. Set to run at boot and let it go I guess.
*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
#Runtime Script
#Tadaen Sylvermane
#Last Edit 2014/1/26
#Variables#
MNTPT=/path/to/mount
#####Begin Script#####
mountshares() {
if mountpoint -q $MNTPT ; then
return 0
else
mount -a
fi
}
while true
do
mountshares
sleep 300
done
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.
Then this... I don't know if it's sloppy or what but I do know that it works. Runs every 5 minutes. Does not spam log (unless it logs pings at which point I give up).
Code:
#!/bin/bash
#Automount Network Shares
#Tadaen Sylvermane
#Last Edit 2014/1/27
#Variables#
##Server 1
SRV1IP=ip
SRV1MNT=mountpoint
SRV1=//ip/share
#####Begin Script#####
automount()
{
##Server 1
if ping -c 1 $SRV1IP ; then
if mountpoint -q $SRV1MNT ; then
return 0
else
mount $SRV1
fi
else
return 0
fi
}
while true
do
automount
sleep 300
done
#####End Script#####
Copy paste and change variables accordingly to add servers.
*EDIT* Thank you for the suggestions and somewhat challenge. I am trying to learn as fast as I can.
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()
# 1st arg: server address (name or ip)
# 2nd arg: local mount point
mymount() {
if ! mountpoint -q $2 then
if ping -c 1 $1 >/dev/null; then
mount $2
fi
fi
}
while true
do
mymount ip1 mountpoint1
mymount ip2 mountpoint2
sleep 300
done
The 300 seconds delay can be reduced to a low value since there's nomore useless messages in log (and, by the way, ping do not write into system log)
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.