Skip to content

Instantly share code, notes, and snippets.

@flyzjhz
Forked from murilopontes/dog.sh
Created December 28, 2016 07:25
Show Gist options
  • Save flyzjhz/1124f13f6f8ffc1c7c08cf6e229839b5 to your computer and use it in GitHub Desktop.
Save flyzjhz/1124f13f6f8ffc1c7c08cf6e229839b5 to your computer and use it in GitHub Desktop.
Openwrt watchdog script
#!/bin/sh
# save dog.sh in /root/dog.sh.
# You can use winscp with scp protocol to do this.
# Using ssh set executation permission and replace the crontab:
# chmod +x /root/dog.sh
# echo "* * * * * /root/dog.sh" | crontab -
# fix wpad / wpad-mini / hostapd stop working bug
logread -l 100 | grep -n "IEEE 802.11: did not acknowledge authentication response"
if [ $? -eq 0 ]; then
/etc/init.d/network restart
fi
# fix kernel bug
n=0
while [ 1 ]; do
#ping with timeout 10 seconds
ping -c 1 -W 10 -w 10 8.8.8.8
ret=$?
echo ping result $ret
if [ $ret -eq 0 ]; then
echo ping ok
exit 0
else
echo ping fail
n=$((n+1))
# when wan-dhcp fail,
# net is unreachable and ping return without any delay
# using sleep 1 avoid fail count overflow too fast
sleep 1
fi
echo fail counter $n
if [ $n -gt 60 ]; then
# in case of wan-dhcp fail total time to reboot is 1 min (60 seconds)
# in case of ping-timeout total time to reboot is 11 min (660 seconds)
reboot
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment