Drcom定时检查

最近线路老出问题,然后端口跟着就没电了,或者令人赞赏有嘉的Drcom会定时弹起\shit-smile,又或者电源没了。总之就是不定时连不上,远程也没法了。能做的就是定时检查能连上外网不,如果不能,就重启登录程序。
中午的票,早上抓紧写个脚本。本想用python的,发现shell可以做到,就是不怎么熟悉。

#!/bin/sh

# kee the drcom online...
#Aug 1, 2017

test_site=cn.bing.com
check_frequency=30m #10s #5m
while true
do
    unreachable=` ping -c 3 -w 10 $test_site | grep '0 received' | wc -l`
    if test $unreachable -gt 0 # networks has been halted, need to re-lanch the drcom
    then
        echo $test_site is unreachable, re-launch the Dr.com
        pkill -x drcomauthsvr
        pkill -x dr   # this is more effecient
        sleep 5s
        dr &
#    else
#        echo 'networks is reachable!'
    fi
sleep $check_frequency
done

Note

  1. pkill -x drcomauthsvr 是要把 61440 的端口清理掉,否则下面重启主程序后依然不能连接上(ps:如果直接杀掉主程序后,退出进程,再启动主程序也可以连上)
  2. wc -l 很nice
  3. 最好放在后台运行 😃
posted @ 2017-08-01 10:12  rotxin  阅读(254)  评论(0编辑  收藏  举报