Trying to get a simple script executed when interface wlan0 is up.

pi@cart:~ $ cat /etc/network/if-up.d/test 
/bin/echo "It's up" > /dev/pts/1

Raspbian 9 (Stretch)

pi@cart:~ $ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION="9 (stretch)"

Just the command performed manually works as intended, but not when placed in a the script to be executed when the interface is up

pi@cart:~ $ /bin/echo "It's up" > /dev/pts/1
It's up
pi@cart:~ $ sudo ifconfig eth0 down
pi@cart:~ $ sudo ifconfig wlan0 down
pi@cart:~ $ sudo ifconfig eth0 up
pi@cart:~ $ sudo ifconfig wlan0 up
pi@cart:~ $ 

Permissions have been set appropriately as well:

pi@cart:~ $ ls -al /etc/network/if-up.d/ | grep test
-rwxr-xr-x 1 root root   33 Sep 20 13:10 test
pi@cart:~ $ 

Even tried placing the script in /etc/dhcp/dhclient-enter-hooks.d/ to no avail.

Has anyone else seen this peculiar behavior?

Edit, added #!/bin/sh to the top of the executable, which made no difference to the outcome

  • 2
    use logger command instead of echo ..... your question is not related to the RPi, so it does not belong on this site ..... it is a linux question – jsotola Sep 20 '18 at 23:52
  • @jsotola Please attempt the steps above, using /usr/bin/logger instead of /bin/echo on the same platform, from an executable file placed in /etc/networking/if-up.d/ and check the /var/log/messages for results – VRS Sep 21 '18 at 13:25

I am not sure what you are trying to achieve; /etc/network/interfaces is NOT a shell script, and in Stretch effectively does nothing.

"this peculiar behavior" is expected i.e. it does nothing.

The Debian networking commands have not been used by Raspbian for 3 years.

See How to set up networking/WiFi for current Raspbian networking.

  • The end goal is to achieve ProxyARP and MDNS forwarding using the Raspberry-Pi. All the commands all work when performed manually from the console, but as soon as the process is attempted to be automated by the wlan0 interface coming up, it does nothing. I have consulted several scenarios to see if something in Stretch had been changed, to no avail – VRS Sep 21 '18 at 13:02
  • @user92012 It is not that these commands don't work - just that Raspbian DOES NOT use Debian networking - it uses dhcpcd as default network manager. Delete /etc/network/interfaces and Raspbian works! – Milliways Sep 21 '18 at 22:14
  • 1
    Thank you for the affirmation that commands aren't issued using /etc/network/interface. What I am trying to achieve is when an interface comes up, execute this command; conversely when the interface goes down, execute a different command. Any suggestions? – VRS Sep 28 '18 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.