DanRoM
Forum Addict
- Joined
- Feb 27, 2009
- Messages
- 10,500
- Location
- Ruhr Area, Germany
- Car(s)
- MX-5 ND, Tracer 900 GT & two bikes
Note: The scripts in this question post are obsolete by the solution posted a few posts below.
I need some help with a Linux script and I hope there are maybe some people here who can help me. Because I'd rather not open an account on StackOverflow or something.
Situation: I have a laptop, and that per definition is mobile. I also have files stored on my NAS at home. So I want to mount the NAS directories after login if the machine is connected to my home network.
System is Ubuntu 18.04, but my approach should be very generic...
The mounting itself is done via CIFS as defined in my /etc/hosts:
This part works fine, or well it would work fine if the laptop had network at the time when fstab is run through.
The manual solution is to execute
after login (and with being connected to the network).
Obviously, I want to automate that.
So... my approach:
However, I'm asked for my password both when I want to run the "local" script as well when I try the "global" one. Providing that, everything works out, meaning the script chain as such works. But a password prompt is obviously a showstopper in a script that's intended to be run in the background via autostart.
Any ideas?
I need some help with a Linux script and I hope there are maybe some people here who can help me. Because I'd rather not open an account on StackOverflow or something.
Situation: I have a laptop, and that per definition is mobile. I also have files stored on my NAS at home. So I want to mount the NAS directories after login if the machine is connected to my home network.
System is Ubuntu 18.04, but my approach should be very generic...
The mounting itself is done via CIFS as defined in my /etc/hosts:
Code:
//<nas-hostname>/<nas-directory> /mnt/<mountpoint> cifs uid=<username>,gid=users,rw,credentials=<path-to-credential-file> 0 0
The manual solution is to execute
Code:
sudo mount -a
Obviously, I want to automate that.
So... my approach:
- a "global" script that wraps the mount command:
Code:#!/bin/sh /usr/bin/sudo /bin/mount -a exit 0
Code:~> ll /usr/local/bin/mountall.sh -rwsr-x--- 1 root nasmounters 287 Jun 11 22:38 /usr/local/bin/mountall.sh*
- an entry in sudoers:
Code:# NAS mounting for selected users %nasmounters ALL=(root) NOPASSWD: /usr/local/bin/mountall.sh
- a "local" script in my user's ~/bin:
Code:#!/bin/sh nashost=<nas-hostname> networksuffix=<common-network-suffix-for-all-hosts> log=~/bin/nas-mount.log if host $nashost|grep -q $nashost$networksuffix then sudo /usr/local/bin/mountall.sh fi exit 0
However, I'm asked for my password both when I want to run the "local" script as well when I try the "global" one. Providing that, everything works out, meaning the script chain as such works. But a password prompt is obviously a showstopper in a script that's intended to be run in the background via autostart.
Any ideas?
Last edited: