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?

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
#!/bin/sh
[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
    logger "iface wan up detected..."
    sh -x /etc/run_when_wan_up.sh
}
exit 0
EOF
1 Like