Last active
May 30, 2020 01:24
-
-
Save 3clypse/065af927922fe8cbb7bd39ea9689bb0f to your computer and use it in GitHub Desktop.
Asuswrt WAN monitor
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 | |
# [Asuswrt WAN monitor] | |
# | |
# The script is quite simple: | |
# - If we have internet connection (succeeded ping), sleep 1 second and set the fail counter to zero. | |
# - Else: If is bigger than the limit set => write in the system log*, reset the WAN and sleep 30 seconds. | |
# | |
# * Visible on <<YOUR_ASUS_ROUTER_IP>>/Main_LogStatus_Content.asp | |
# Usage: | |
# 1) Add this script on /jffs/scripts/ | |
# 2) Ensure execution permission running: chmod +x wan-monitor.sh | |
# 3) Add the script into the startup service: echo "sh /jffs/scripts/wan-monitor.sh & # wan-monitor" >> /jffs/scripts/services-start | |
# 4) Reboot your router. Enjoy. | |
TARGET="google.com" | |
COUNT=0 | |
MAX_FAILING=5 | |
while true | |
do | |
ping -c 1 $TARGET > /dev/null 2>&1 | |
PING=$? | |
if [ $PING = 0 ] ; then | |
COUNT=0 | |
sleep 1 | |
else | |
if [ "$COUNT" -gt "$MAX_FAILING" ]; then | |
logger -t wan-monitor "Restarting WAN..." | |
service restart_wan | |
sleep 30 | |
fi | |
COUNT=$((COUNT+=1)) | |
sleep 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment