Reconnecting to network shares

From LXF Wiki

Here's a little gem I found in a recent LXF.

Often can be the case that your files server falls over, network wobbles, you boot your computers in the wrong order, and you find that you can't reach your SaMBa shares which are set up and working properly. Usually you have to open a terminal, "sudo mount -a" or something similar. Easy for you, but then the work colleague, housemate, wife just can't get their heads around it ..

First, drop a text file called "reconnect" in /usr/local/bin

 #! /bin/bash
 # this is what would be in the fstab file, or use mount -a
 mount -t smbfs //server/share /mnt/share
 

In the terminal:

 #cd /usr/local/bin
 #chown user:user reconnect
 #chmod a+x reconnect

"user" is the user who will be using the script

Tricky bit now .. track down your sudoers file. Tread carefully here - I made a pig's-ear of this using chmod and nano and had to use the recovery-kernel to put things back together. This is where you open firefox and type "visudo" in the google box!

 #visudo -f sudoers

add to the end:

 # added by me, hope nothing breaks
 %users ALL=nopasswd /usr/local/bin/reconnect
 

"%users" - the group that is allowed to use the "reconnect" script.

Now, create a launcher on the desktop. In the command box, enter

 sudo reconnect
 

The entry in the visudoers file means that the script is allowed run with requiring a password when the "sudo" command is issued by the launcher.

All things being equal, if you "umount /mnt/*", your shares 'break' - when you double-click the launcher on your desktop nothing appears to happen - except your shares will be linked up again.