-
-
Save lichti/3417a45eeb052da971c1d0b9c4027635 to your computer and use it in GitHub Desktop.
Openwrt watchdog script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
thanx a lot!