Reputation: 153
I have a linux box connected to a router via an ethernet cable. The cable is never unplugged and the linux box is always on. My goal is to have a command executed on the linux box every time the router is rebooted.
This question is quite similar to this question but the suggested solution doesn't seem to work. More specifically:
inotifywait -e modify /sys/class/net/eth0/carrier; echo 'Change detected'
does never detect a change (even in the case the cable is unplugged from the pc), because according to this answer the command inotifywait
does not work in /sys
inotifywait -e modify /etc/network/if-up.d/avahi-daemon
does not detect any change when the router is rebootedUpvotes: 2
Views: 4479
Reputation: 6037
You can start a script after the linux box gets connected using up
(requires ifplugd
to be installed )
#/etc/network/interfaces
auto eth0
iface eth0 inet dhcp
up /etc/network/yourscript.sh
However, there keep in mind that if you disconnect the cable (and plug in in after a while), the script also starts even though the router might not have been restarted.
--edit--
alternatively , place your script in
/etc/network/if-up.d/
(make sure it is executable and restart networking after changes.)
Upvotes: 1
Reputation: 131
Depending on the Linux distribution on that router the correct way of running a command at startup/reboot is to create a startup script, or add the command to /etc/rc.local
Upvotes: 0