Run a script when an interface goes up and down

Is there a way to be notified and run a script when the pppoe-wan interface goes up and down?

1 Like

Just place the script at /etc/hotplug.d/iface/ (and have a look at the other scripts there to see what parameters your script is going to receive).

3 Likes

Thank you; that is what I was looking for.

Just an example if needed (change ACTION to ifdown to detect down state):

cat<<'EOF' > /etc/hotplug.d/iface/99-ifup-wan
#!/bin/sh
[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
    logger "iface wan up detected..."
    sh -x /etc/run_when_wan_up.sh
}
exit 0
EOF
2 Likes

Why doesn't this script work when I change the interface name to "bat0" (batman-adv interface)?

I'd like to run a script when the mesh becomes disconnected (= 0 partners connected). I also did chmod +x

Potentially since the /etc/hotplug.d/iface scripts are called only for OpenWrt virtual interfaces like wan (at least I have this issue on a turris only since the next to last update, before it just worked for pppeo-wan and even eth0). But the scripts in /etc/hotplug.d/net are still called, so you might put your script in there, just note that these come with different variables in the environment.

1 Like

Thanks for your reply :slight_smile: . I've tried to put the following script there with chmod +x and then disconnect the batman mesh partner to test. The /tmp/test.txt wasn't created.

chmod +x /etc/hotplug.d/net/99-batman

#!/bin/sh
#
echo "---" >> /tmp/test.txt
env >> /tmp/test.txt
echo "---" >> /tmp/test.txt

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.