I use my Raspberry Pi Model B with Raspbian as a server and I want to know (if it is possible) how to make that the Raspberry pi send itself a halt command when I unplug the Ethernet cable (eth0)
Any help will be very appreciated.
I use my Raspberry Pi Model B with Raspbian as a server and I want to know (if it is possible) how to make that the Raspberry pi send itself a halt command when I unplug the Ethernet cable (eth0)
Any help will be very appreciated.
post-down script;
Write a script to call 'reboot' as /path/to/script.sh
Edit your /etc/network/interfaces file and add a line just below your eth0 config.
auto eth0
iface eth0 inet static
name "Ethernet0"
address 192.168.1.1
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0
gateway 192.168.1.254
post-down /path/to/script.sh
Your /path/to/script.sh script will run when your eth0 down.
Just drop your shutdown script into the /etc/network/if-post-down.d
directory. Remember to make the script executable, as well.
#!/bin/sh
/sbin/shutdown -h now
Create a cron job every minute to ping your gateway, the moment the ping is lost- issue halt command. You can check for example for 2 consecutive pings to be sure is not a glitch.