Skip to content

Instantly share code, notes, and snippets.

@dmelo
Last active May 27, 2016 03:53
Show Gist options
  • Save dmelo/fb935be074100d0c48f9d847f2eaf631 to your computer and use it in GitHub Desktop.
Save dmelo/fb935be074100d0c48f9d847f2eaf631 to your computer and use it in GitHub Desktop.
watchdog script to reboot my old notebook every time it loses connection with the network router.
#!/bin/bash
function flog() {
DATE=$(date)
echo "$DATE - $1"
}
function freboot() {
echo "TIME TO REBOOT"
/usr/sbin/reboot
}
while [ 1 ]
do
COUNT=$(ping -c 1 192.168.0.1 > /dev/null && echo 0 || echo `expr $COUNT + 1`)
flog "$([ $COUNT -ge 5 ] && freboot || echo "COUNT=$COUNT")"
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment