# When the pings fail, power off the computer REMOTE_IP='192.168.1.2' if [ "$1" == '--help' ] || [ "$1" == '-h' ] then echo '' echo 'This script checks if the pings to $REMOTE_IP work.' echo 'If they do not, it powers off this computer.' echo '' echo 'To avoid this, create a file called /usr/local/etc/cron_poweroff.lock' echo '(You can do this by typing "sudo touch /usr/local/etc/cron_poweroff.lock".)' echo '' echo 'It should be run every night (if the PC is on) as root, by a cronjob.' echo '(You can configure this in /etc/crontab.)' echo '' exit 0 fi if [ -e /usr/local/etc/cron_poweroff.lock ] then exit 1 fi while fping -q $REMOTE_IP do sleep 7m if [ -e /usr/local/etc/cron_poweroff.lock ] then exit 1 fi done poweroff