You are not logged in.

#1 2012-11-25 20:32:23

Ruffman
Member
Registered: 2012-04-07
Posts: 15

/etc/NetworkManager/dispatcher.d/ scripts not working

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/log

If 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

#2 2012-11-25 21:08:46

ijanos
Member
From: Budapest, Hungary
Registered: 2008-03-30
Posts: 443

Re: /etc/NetworkManager/dispatcher.d/ scripts not working

Does it have the execute flag? chmod +x /etc/NetworkManager/dispatcher.d/50_mount_homenet

Offline

#3 2012-11-25 21:25:39

Ruffman
Member
Registered: 2012-04-07
Posts: 15

Re: /etc/NetworkManager/dispatcher.d/ scripts not working

as you can see above

# ls -la 10_debug
-rwxr-xr-x 1 root root 104 Nov 25 21:06 10_debug

anyone has the right to execute it

Offline

#4 2012-11-25 21:41:10

ijanos
Member
From: Budapest, Hungary
Registered: 2008-03-30
Posts: 443

Re: /etc/NetworkManager/dispatcher.d/ scripts not working

you are right, I've tottaly missed that line. No idea then sad

the dispatch script works for me.

Offline

#5 2012-11-25 22:19:24

Ruffman
Member
Registered: 2012-04-07
Posts: 15

Re: /etc/NetworkManager/dispatcher.d/ scripts not working

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-netfs

Only 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:

WIKI wrote:

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

#6 2012-11-25 22:21:27

ijanos
Member
From: Budapest, Hungary
Registered: 2008-03-30
Posts: 443

Re: /etc/NetworkManager/dispatcher.d/ scripts not working

My dispatcher scripts run just fine with 755

Offline

#7 2012-11-25 23:07:43

Ruffman
Member
Registered: 2012-04-07
Posts: 15

Re: /etc/NetworkManager/dispatcher.d/ scripts not working

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      
fi

The 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

#8 2013-05-03 03:26:38

jazzcat
Member
Registered: 2012-10-10
Posts: 25

Re: /etc/NetworkManager/dispatcher.d/ scripts not working

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      
fi

Offline

Board footer

Powered by FluxBB