[SOLVED] Dispatcher script doesn't work.

Technical issues/questions of an intermediate or advanced nature.
Post Reply
babam
Black ninja
Black ninja
Posts: 57
Joined: 16 Nov 2016, 10:30
Distribution: Porteus 3.2.2
Location: Rainy city

[SOLVED] Dispatcher script doesn't work.

Post#1 by babam » 04 Jun 2019, 17:00

How to get /etc/NetworkManager/dispatcher.d/XXX.sh to work.

Code: Select all

$ ls -l /etc/NetworkManager/dispatcher.d/01-test.sh
-rwxr-xr-x 1 root root 81 May 31 10:16 /etc/NetworkManager/dispatcher.d/01-test.sh

Code: Select all

$ cat /etc/NetworkManager/dispatcher.d/01-test.sh
 
#!/bin/bash

if [ "$2" = "up" ]; then
    echo "$2" > /tmp/test.txt

elif [ "$2" = "down" ]; then
    echo "$2" > /tmp/test.txt
fi
After disconnecting/connecting Wifi/Ethernet connection.

Code: Select all

$ cat /tmp/test.txt
cat: /tmp/test.txt: No such file or directory
Thanks.
Last edited by babam on 07 Jun 2019, 05:16, edited 1 time in total.
Sorry, my English is bad.

User avatar
Ed_P
Contributor
Contributor
Posts: 4916
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 Cinnamon 64-bit ISO
Location: Western NY, USA

Dispatcher script doesn't work

Post#2 by Ed_P » 04 Jun 2019, 20:00

What happens if $2 is not "up" and not "down"?

Maybe something like this would work better.

Code: Select all

#!/bin/bash

if [ "$2" == "up" ] || [ "$2" == "down" ]; then
   echo "$2" > /tmp.test.txt
else
   echo "$2 is not up or down" > /tmp/test.txt
fi 
And make sure your .sh file is executable.

Code: Select all

chmod +x 01-test.sh
Ed

babam
Black ninja
Black ninja
Posts: 57
Joined: 16 Nov 2016, 10:30
Distribution: Porteus 3.2.2
Location: Rainy city

Dispatcher script doesn't work

Post#3 by babam » 04 Jun 2019, 22:49

Ed_P wrote:
04 Jun 2019, 20:00
What happens if $2 is not "up" and not "down"?

Maybe something like this would work better.

Code: Select all

#!/bin/bash

if [ "$2" == "up" ] || [ "$2" == "down" ]; then
   echo "$2" > /tmp.test.txt
else
   echo "$2 is not up or down" > /tmp/test.txt
fi 
Still doesn't work

Code: Select all

$ cat /tmp/test.txt
cat: /tmp/test.txt: No such file or directory
Ed_P wrote:
04 Jun 2019, 20:00
And make sure your .sh file is executable.

Code: Select all

chmod +x 01-test.sh

Code: Select all

$ ls -l /etc/NetworkManager/dispatcher.d/01-test.sh
-rwxr-xr-x 1 root root 81 May 31 10:16 /etc/NetworkManager/dispatcher.d/01-test.sh
Sorry, my English is bad.

User avatar
Ed_P
Contributor
Contributor
Posts: 4916
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 Cinnamon 64-bit ISO
Location: Western NY, USA

Dispatcher script doesn't work

Post#4 by Ed_P » 05 Jun 2019, 04:04

If you manually run the 01-test.sh script from the command line do any errors show up? If not try "01-test.sh xx on" and "01-test.sh xx off" and "01-test.sh xx yy", each followed with a "ls -l /tmp"
Ed

babam
Black ninja
Black ninja
Posts: 57
Joined: 16 Nov 2016, 10:30
Distribution: Porteus 3.2.2
Location: Rainy city

Dispatcher script doesn't work

Post#5 by babam » 05 Jun 2019, 04:17

Code: Select all

$ ./01-test.sh xxx up

Code: Select all

$ cat /tmp/test.txt
up

Code: Select all

$ ./01-test.sh xxx down

Code: Select all

$ cat /tmp/test.txt
down
Sorry, my English is bad.

User avatar
Ed_P
Contributor
Contributor
Posts: 4916
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 Cinnamon 64-bit ISO
Location: Western NY, USA

Dispatcher script doesn't work

Post#6 by Ed_P » 05 Jun 2019, 18:42

So, the test.sh script works it just doesn't work in /etc/NetworkManager/dispatcher.d/. Why that is I have no idea. Sorry. :(
Ed

User avatar
Ed_P
Contributor
Contributor
Posts: 4916
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 Cinnamon 64-bit ISO
Location: Western NY, USA

Dispatcher script doesn't work

Post#7 by Ed_P » 05 Jun 2019, 21:05

Ed

babam
Black ninja
Black ninja
Posts: 57
Joined: 16 Nov 2016, 10:30
Distribution: Porteus 3.2.2
Location: Rainy city

[SOLVED] Dispatcher script doesn't work.

Post#8 by babam » 07 Jun 2019, 05:13

@Ed_P, Thanks.

Strange, now the dispatcher script can work.

Code: Select all

# /etc/rc.d/rc.networkmanager restart
Sorry, my English is bad.

User avatar
Ed_P
Contributor
Contributor
Posts: 4916
Joined: 06 Feb 2013, 22:12
Distribution: 4.0 Cinnamon 64-bit ISO
Location: Western NY, USA

[SOLVED] Dispatcher script doesn't work.

Post#9 by Ed_P » 07 Jun 2019, 18:03

:Yahoo!:

What did you do to make it work?
Ed

babam
Black ninja
Black ninja
Posts: 57
Joined: 16 Nov 2016, 10:30
Distribution: Porteus 3.2.2
Location: Rainy city

[SOLVED] Dispatcher script doesn't work.

Post#10 by babam » 09 Jun 2019, 21:17

Restart Networkmanager

Code: Select all

# /etc/rc.d/rc.networkmanager restart
Sorry, my English is bad.

Post Reply