You are not logged in.
I want to auto-(un)mount my NAS network storage when I'm connecting to my home-network. To mount it I just have to type mount /media/homenet and everything works when I'm connected at home. So I tried to write a script inside /etc/NetworkManager/dispatcher.d/50_mount_homenet as I realized, that it is not running. To debug it I wrote a simple script:
# ls -la 10_debug
-rwxr-xr-x 1 root root 104 Nov 25 21:06 10_debug
# cat 10_debug
#! /bin/bash
echo "`date`" > /tmp/log
echo "$1" >> /tmp/log
echo "$2" >> /tmp/logIf I connect disconnect to any network there is no entry inside /tmp/log, but if I execute it myself, it prints the date and the first and second parameter to /tmp/log.
I have no idea why this is not working. I have the latest arch upgardes, though networkmanager 0.9.6.4-1 with systemd 195-2.
Any idea appreciated
Offline
Does it have the execute flag? chmod +x /etc/NetworkManager/dispatcher.d/50_mount_homenet
Offline
as you can see above
# ls -la 10_debug
-rwxr-xr-x 1 root root 104 Nov 25 21:06 10_debuganyone has the right to execute it
Offline
you are right, I've tottaly missed that line. No idea then
the dispatch script works for me.
Offline
Oh, I think I just found (accidently) a solution:
I searched pacman for networkmanager and found several "dispatcher" scripts such as the community/networkmanager-dispatcher-netfs packed. I installed it, and added the execution of my 10-debug script on top, just to wonder that it works now.
I looked at the permissions of that script and BINGO:
# ls -la 10-netfs
-rwx------ 1 root root 225 Nov 25 23:09 10-netfsOnly root is allowed to do anything. I changed the permissions of my debug-script to see it working afterwards.
I think this warning inside the Wiki:
Warning: For security reason. You should disable write access for group and other. For example use 755 mask. In other case it can refuse to execute script, with error message "nm-dispatcher.action: Script could not be executed: writable by group or other, or set-UID." in /var/log/messages.log
should get updated to something like
"...You must use 700 mask as permissions for security reasons...",
but I don't want to change it as I'm not really shure. Maybe someone can confirm this.
Offline
My dispatcher scripts run just fine with 755
Offline
very strange...
I removed the dispatcher packed changed to 755 and... it works. No Idea what the heck was wrong the first time.
No I have a chicken egg problem:
I have saved samba credentials inside
/etc/samba/auth.fritz.box.ftpuser
with username and pass as well as an entry inside my fstab:
//fritz.box/Fritz.NAS /media/FritzBox cifs users,noauto,credentials=/etc/samba/auth.fritz.box.ftpuser 0 0
I use noauto because on boot the wlan isn't connected yet. So If NetworkManager has booted I can just type mount /media/FritzBox and everything works, as well as umount /media/FritzBox
If I disconnect FritzBox without unmounting my samba share the System will hang (at least on shutdown, or anytime I want to access /media folder). So I wrote a script for the dispatcher:
bssid=`iwconfig | grep -o 'ESSID:".*"' | grep -oe '".*"'` 2>/dev/null
echo "$bssid" >> /tmp/log
if [ "$bssid" = '"Sunny WLAN 7360 SL"' ]; then
state=$2
if [ "$state" = "up" ]; then
mount /media/FritzBox/
else
umount /media/FritzBox/
fi
fiThe mount part works as expected, but the unmount not. I guess the WLAN is down, NetworkManager triggers my script - to late. It seems that there is no "pre-down" hook. What can I do to prevent this?
Offline
I was having the same problem with umount, and found adding lazy umount resolved the issue. ie,
bssid=`iwconfig | grep -o 'ESSID:".*"' | grep -oe '".*"'` 2>/dev/null
echo "$bssid" >> /tmp/log
if [ "$bssid" = '"Sunny WLAN 7360 SL"' ]; then
state=$2
if [ "$state" = "up" ]; then
mount /media/FritzBox/
else
umount -l /media/FritzBox/
fi
fiOffline