NECルータ自動再起動

Diary
NEC router

すぐハングアップするルータの対処方法を書きます。
こちらの続きです。https://matsu.teraren.com/blog/2009/09/10/atermbr-745f68/

1,2日に1回NATテーブルがオーバーフローしてインターネットに繋がらなくなるルータの対処方法です。

普通なら、NATテーブルがあふれたら管理画面開いて、ログ見て、ERRORという文字が出ていたらルータの再起動。という作業をやらなければならない・・・これがめんどくさいという人のために自動化するシェルスクリプト書きました。

仕様

  • 5秒に1回、ルータの画面をチェックしてERROR文字が10行以上出力されていたらルータを再起動します
  • ファイルはSJISで保存してください
  • デーモンとして動きます
  • VoIP利用中だったら、切れるまで待ちます

ソースコード

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 Reset 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 Reset log
2009-10-30 16:54:14.038838500 Reboot
2009-10-31 10:45:17.594545500 Reset log
2009-10-31 10:45:17.673467500 Reboot
2009-11-02 12:12:44.943487500 Reset log
2009-11-02 12:12:45.022605500 Reboot

コメント