Skip to content

Instantly share code, notes, and snippets.

@matsubo
Last active September 12, 2023 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsubo/2182530 to your computer and use it in GitHub Desktop.
Save matsubo/2182530 to your computer and use it in GitHub Desktop.
Restart NEC router when NAT buffer pool is overflow.
#!/bin/bash
# Reboot NEC router if NAT errors are saved in router status page.
# - Checks VoIP status.
# - Run as daemon.
# - Encoding have to be Shift-JIS.
#
# @copytright Yuki Matsukura
# @contact https://matsu.teraren.com/blog/
#
USER="admin"
PASSWORD="admin"
HOST="http://192.168.0.1"
echo "Starting."
while :
do
ERRORCOUNT=`wget -q -O - --user=$USER --password=$PASSWORD $HOST/log_main.html|grep ERROR | wc -l`
if [ $ERRORCOUNT -lt 10 ]
then
#    echo `date` "Error not found"
sleep 5
continue
fi
# check current tel connection
# 2:unused 0:in use
CONNECTION=`wget -q -O - --user=$USER --password=$PASSWORD $HOST/info_tel.html | grep '未通話' | wc -l`
if [ $CONNECTION -eq 0 ]
then
echo "Waiting for disconnecting the tel line."
sleep 1
continue
fi
# Reset log to avoid double count
echo "Reset log"
wget -q -O - --user=$USER --password=$PASSWORD --post-data 'No00208010=&No004c0000=&No00F6D011&No00420000=%93o%98%5E' $HOST/log_main.html > /dev/null
# Reset the router
echo "Reboot"
wget -q -O - --user=$USER --password=$PASSWORD --post-data 'No00420011=reboot&No00420000=%93o%98%5E' $HOST/index_menu.html > /dev/null
# wait for the router is coming up
sleep 30
done
#!/bin/sh
exec 2>&1
exec sh -c 'exec envuidgid daemon softlimit -o10 ./router_restart.sh'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment