I was looking at How to shut down RPi when running headless and really happy to see the awesomeness!
So, is it possible to use udev rule to shutdown my Pi when I switch off the router that connects my Pi with the eth cable?
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It only takes a minute to sign up.Sign up to join this community
You could write a script that checks the content of the file
/sys/class/net/eth0/operstate in a loop. When the state shows
down execute the
halt command on your RPi.
while true grep 'down' /sys/class/net/eth0/operstate && halt sleep 5 done
Or, even better with a cron job run, say, every 2 minutes:
*/2 * * * * root /bin/grep 'down' /sys/class/net/eth0/operstate && halt -p