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).


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
[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
    logger "iface wan up detected..."
    sh -x /etc/
exit 0

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

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.