Skip to content

Instantly share code, notes, and snippets.

@lichti
Forked from flyzjhz/dog.sh
Created January 2, 2020 15:32
Show Gist options
  • Save lichti/3417a45eeb052da971c1d0b9c4027635 to your computer and use it in GitHub Desktop.
Save lichti/3417a45eeb052da971c1d0b9c4027635 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
@kalashnikoff
Copy link

thanx a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment