Based on information, any file inside of
/etc/NetworkManager/dispatcher.d/
is suppose to receive 2 possible commands from
NetworkManager
to find out what these commands might be we simply
look at the source of one of the scripts that is already in
/etc/NetworkManager/dispatcher.d/
so let's do that.
cd /etc/NetworkManager/dispatcher.d/
ls
00-netreport 05-netfs 10-dhclient
vi 00*
nothing here.
gedit 05*
excellent.
#!/bin/sh
export LC_ALL=C
if [ "$2" = "down" ]; then
/sbin/ip route ls | grep -q ^default || {
[ -f /var/lock/subsys/netfs ] && /etc/rc.d/init.d/netfs stop || :
} && { :; }
fi
if [ "$2" = "up" ]; then
/sbin/ip -o route show dev "$1" | grep -q '^default' && {
/sbin/chkconfig netfs && /etc/rc.d/init.d/netfs start || :
} || { :; }
fi
let's copy this and create a file named
test
let's only use what we need which is "up".
file: test
#!/bin/sh
export LC_ALL=C
if [ "$2" = "up" ]; then
/sbin/ip -o route show dev "$1" | grep -q '^default' && {
/sbin/chkconfig netfs && /etc/rc.d/init.d/netfs start || :
} || { :; }
fi
let's modify it so that it can execute something "visually" that we can test it with.
#!/bin/sh
export LC_ALL=C
if [ "$2" = "up" ]; then
gedit test.txt
fi
Result:
Not Working.
let's modify it in a way so that it may understand.
#!/bin/sh
export LC_ALL=C
if [ "$2" = "up" ]; then
/sbin/ip -o route show dev "$1" | grep -q '^default' && {
gedit test.txt || :
} || { :; }
fi
rebooting..
result:
nothing
SOLVED:
here's the smallest possible code from the chosen answer:
( that i was able to create )
case "$2" in
up)
touch /root/Desktop/ooo
;;
esac
i needed to make it smaller because i reformat my machine often and then run a script to automatically set these things up. so in the future i simply will run
cat >> /etc/NetworkManager/dispatcher.d/test << EOF
case "\$2" in
up)
touch /root/Desktop/ooo
;;
esac
EOF
chmod +x /etc/NetworkManager/dispatcher.d/test
in other words the $ has to be escaped with "cat>>
" thing.