Executing a command when the network gets up
by Rob0311 from LinuxQuestions.org on (#51ZTS)
Hello everyone,
I am a retired engineer who tries to move all my systems from Windows 7 to Linux (mint in most cases), and already done for a laptop and a CNC controller.
I now replaced the Windows 7 of my desktop/server with Linux mint as well, running kernel 5.6.0
On my Windows system I used a 40" UHD TV screen via a HDMI port. The TV does not turn on when I switch my system on, but it responds to a WOL signal. On my Windows system I made a simple system service that sends the wakeup message via my LAN. I am now trying to replicate that in Linux.
I found the etherwake utility, and sending 'sudo etherwake -i enp5s0f1 70:54:b4:44:bc:ca' from my account works perfectly.
Since it is hard to login with a completely black screen, the WOL message needs to be sent as soon as the network is up. I am new to Linux, and this is where I have some problems, as I am not very familiar (yet) with the command language.
In /etc/network/ I found the directories if-up.d, if-down.d, if-pre-up.d etc) and I assume that systemd runs those contents when needed. Is that correct?
Above that directory sits a file with the following content:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
From the man pages this looks like a loop, and I assume that systemd starts this loop when required?
The man pages for IFACE also specify a post-up 'command'
Would adding this to the above file run a loop until the interface is up for instance:
auto enp5s0f1
iface enp5s0f1
post-up /etc/network/<some_directory>/etherwake -i enp5s0f1 70:54:b4:44:bc:ca
That actually does not work. What would be the right approach The system has two Ethernet adapters, the enp5s0f1 is only used for the TV.
(Another issue is if the network is shut down during sleep, or if I need to call etherwake from another event as well. But that is a next step)
Thanks for help,
Rob


I am a retired engineer who tries to move all my systems from Windows 7 to Linux (mint in most cases), and already done for a laptop and a CNC controller.
I now replaced the Windows 7 of my desktop/server with Linux mint as well, running kernel 5.6.0
On my Windows system I used a 40" UHD TV screen via a HDMI port. The TV does not turn on when I switch my system on, but it responds to a WOL signal. On my Windows system I made a simple system service that sends the wakeup message via my LAN. I am now trying to replicate that in Linux.
I found the etherwake utility, and sending 'sudo etherwake -i enp5s0f1 70:54:b4:44:bc:ca' from my account works perfectly.
Since it is hard to login with a completely black screen, the WOL message needs to be sent as soon as the network is up. I am new to Linux, and this is where I have some problems, as I am not very familiar (yet) with the command language.
In /etc/network/ I found the directories if-up.d, if-down.d, if-pre-up.d etc) and I assume that systemd runs those contents when needed. Is that correct?
Above that directory sits a file with the following content:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
From the man pages this looks like a loop, and I assume that systemd starts this loop when required?
The man pages for IFACE also specify a post-up 'command'
Would adding this to the above file run a loop until the interface is up for instance:
auto enp5s0f1
iface enp5s0f1
post-up /etc/network/<some_directory>/etherwake -i enp5s0f1 70:54:b4:44:bc:ca
That actually does not work. What would be the right approach The system has two Ethernet adapters, the enp5s0f1 is only used for the TV.
(Another issue is if the network is shut down during sleep, or if I need to call etherwake from another event as well. But that is a next step)
Thanks for help,
Rob