-
-
Save hitesh83/4b3a11a04d2203dbc93c8002a64a86ef to your computer and use it in GitHub Desktop.
Openwrt watchdog script
This file contains hidden or 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 | |
#Trying to restart WAN interface | |
ifdown wan && ifup wan | |
#waiting for 10sec to reconnect | |
sleep 10 | |
#checking internet now | |
ping -c 1 -W 10 -w 10 8.8.8.8 | |
ret=$? | |
if [ $ret -eq 0 ]; then | |
echo ping ok | |
exit 0 | |
else | |
echo all failed rebooting now | |
reboot | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment