NECルータ自動再起動

すぐハングアップするルータの対処方法を書きます。
こちらの続きです。http://matsu.tymy.net/blog/2009/09/10/atermbr-745f68/
1,2日に1回NATテーブルがオーバーフローしてインターネットに繋がらなくなるルータの対処方法です。
普通なら、NATテーブルがあふれたら管理画面開いて、ログ見て、ERRORという文字が出ていたらルータの再起動。という作業をやらなければならない・・・これがめんどくさいという人のために自動化するシェルスクリプト書きました。
仕様
- 5秒に1回、ルータの画面をチェックしてERROR文字が10行以上出力されていたらルータを再起動します
- ファイルはSJISで保存してください
- デーモンとして動きます
- VoIP利用中だったら、切れるまで待ちます
ソースコード
#!/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 http://matsu.tymy.net/blog/about/ # @version $Id:$ 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 "Rest 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
daemontoolsで起動する場合のrunファイルの中身
#!/bin/sh exec 2>&1 exec sh -c 'exec envuidgid daemon softlimit -o10 ./router_restart.sh'
しばらく運用するとdaemontoolsのログにはこんな感じで出力される
[root@dev1 /var/log/routerreset]# cat current|tai64nlocal 2009-10-30 10:36:29.241894500 Starting. 2009-10-30 11:10:50.983588500 Rest log 2009-10-30 11:10:51.063590500 Reboot 2009-10-30 16:53:41.973878500 Waiting for disconnecting the tel line. 2009-10-30 16:53:43.145824500 Waiting for disconnecting the tel line. 2009-10-30 16:53:44.322821500 Waiting for disconnecting the tel line. 2009-10-30 16:53:45.495036500 Waiting for disconnecting the tel line. 2009-10-30 16:53:46.674632500 Waiting for disconnecting the tel line. 2009-10-30 16:53:47.847190500 Waiting for disconnecting the tel line. 2009-10-30 16:53:49.020860500 Waiting for disconnecting the tel line. 2009-10-30 16:53:50.191697500 Waiting for disconnecting the tel line. 2009-10-30 16:53:51.367155500 Waiting for disconnecting the tel line. 2009-10-30 16:53:52.552524500 Waiting for disconnecting the tel line. 2009-10-30 16:53:53.727068500 Waiting for disconnecting the tel line. 2009-10-30 16:53:54.917356500 Waiting for disconnecting the tel line. 2009-10-30 16:53:56.128064500 Waiting for disconnecting the tel line. 2009-10-30 16:53:57.307613500 Waiting for disconnecting the tel line. 2009-10-30 16:53:58.506647500 Waiting for disconnecting the tel line. 2009-10-30 16:53:59.703276500 Waiting for disconnecting the tel line. 2009-10-30 16:54:00.883237500 Waiting for disconnecting the tel line. 2009-10-30 16:54:02.064220500 Waiting for disconnecting the tel line. 2009-10-30 16:54:03.245124500 Waiting for disconnecting the tel line. 2009-10-30 16:54:04.424067500 Waiting for disconnecting the tel line. 2009-10-30 16:54:05.610304500 Waiting for disconnecting the tel line. 2009-10-30 16:54:06.794509500 Waiting for disconnecting the tel line. 2009-10-30 16:54:07.989049500 Waiting for disconnecting the tel line. 2009-10-30 16:54:09.189855500 Waiting for disconnecting the tel line. 2009-10-30 16:54:10.381022500 Waiting for disconnecting the tel line. 2009-10-30 16:54:11.586075500 Waiting for disconnecting the tel line. 2009-10-30 16:54:12.774096500 Waiting for disconnecting the tel line. 2009-10-30 16:54:13.956662500 Rest log 2009-10-30 16:54:14.038838500 Reboot 2009-10-31 10:45:17.594545500 Rest log 2009-10-31 10:45:17.673467500 Reboot 2009-11-02 12:12:44.943487500 Rest log 2009-11-02 12:12:45.022605500 Reboot
| 印刷 | この記事は Yuki Matsukura によって 2009/11/2 月曜日 13:56:40 に投稿されました, Diary 以下に保存されています。 RSS 2.0 を通してコメントをフォローする。 コメントを残すか、ご自分のサイトからトラックバックできます。 |