Skip to content

Instantly share code, notes, and snippets.

@3clypse
Last active May 30, 2020 01:24
Show Gist options
  • Save 3clypse/065af927922fe8cbb7bd39ea9689bb0f to your computer and use it in GitHub Desktop.
Save 3clypse/065af927922fe8cbb7bd39ea9689bb0f to your computer and use it in GitHub Desktop.
Asuswrt WAN monitor
#!/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