You are not logged in.

#1 2011-09-27 01:35:38

Dumbledore
Member
From: Mumbai, India
Registered: 2011-04-27
Posts: 56

Need help with NetworkManager dispatcher script

Dear *,

Please have a look at the script below. All it does is to start autofs as an interface comes up and make symlinks to my shares in $HOME and remove these shares and close autofs when _all_ interfaces die. However, the problem is while the "down" part of the script works fine, the "up" part does not!

My guess is that when the script exits it closes all child processes started with it including the one that started autofs. Does that make any sense? It's just a hunch. I've seen that the wiki uses 'exec' before these commands which is where I got this hunch. But the problem is that I need the script to also make the symlinks while exec will make the script exit immediately. I tried using '&' after the autofs command which didn't work either.

Any ideas on how this can be achieved?

#!/bin/sh

function link {
    for d in elib temp home ; do ln -s /media/shares/"$d" ~/"$d" ; done
}

function delink {
    for d in elib temp home ; do unlink ~/"$d" ; done
}

case "$2" in
    "up")
        sudo /etc/rc.d/autofs start &
        link
        ;;
    "down")
        if [ ! $(nm-tool | grep State | cut -f 2 -d ' ') == "connected" ]; then
            delink
            sudo /etc/rc.d/autofs stop
        fi
        ;;
esac

Also, another thing, the script above is in a folder in my $HOME and symlinked in /usr/local/bin. The actual script being called by nm_dispatcher is the following:

#!/bin/sh

sudo -u username /usr/local/bin/nm_autofs $*

exit 0

The funny thing is that unless I put the full path to the script, i.e. /usr/local/bin/nm_autofs, the script doesn't run. By doesn't run I mean nm_dispatcher can't call nm_autofs from /usr/local/bin; while if I directly call the script from a terminal, it works as expected.

Is there an explanation that I'm missing? Even though /usr/local/bin is in root's $PATH, why can't I just call nm_autofs directly above?

Looking forward to suggestions and advice. Thanks in advice!

Last edited by Dumbledore (2011-09-27 01:38:58)


GNU/Linux: Keep your options "open".

Offline

Board footer

Powered by FluxBB