From 6165b043f87a8f4ec5db03c560eba0dd73d83bc7 Mon Sep 17 00:00:00 2001 From: BurningC4 Date: Thu, 2 Sep 2021 23:57:31 +0800 Subject: [PATCH] Update shadowsocks_watchdog.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 触发任务后会随机延迟0-9秒开始测试 不再需要在cron中设定重定向的日志文件,也不再需要定时清空文件 设定为在周日1:00清空日志文件 --- shadowsocks_watchdog.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/shadowsocks_watchdog.sh b/shadowsocks_watchdog.sh index d5dde6c..cef3955 100755 --- a/shadowsocks_watchdog.sh +++ b/shadowsocks_watchdog.sh @@ -1,18 +1,23 @@ #!/bin/sh -# version: 0.0.1 +# version: 0.0.2 LOGTIME=$(date "+%Y-%m-%d %H:%M:%S") +LOGFILE=/var/log/ss_watchdog.log +if [ `date +%w%H%M` == 70100 ];then + echo -n "" > $LOGFILE +fi +sleep `awk 'BEGIN{srand();print int(rand()*10)}'` wget --spider --quiet --tries=1 --timeout=10 https://www.google.com/ if [ "$?" == "0" ]; then - echo '['$LOGTIME'] No Problem.' + echo '['$LOGTIME'] No Problem.' >> $LOGFILE exit 0 else wget --spider --quiet --tries=1 --timeout=10 https://www.baidu.com/ if [ "$?" == "0" ]; then - echo '['$LOGTIME'] Problem decteted, restarting shadowsocks.' + echo '['$LOGTIME'] Problem decteted, restarting shadowsocks.' >> $LOGFILE /etc/init.d/shadowsocks restart else - echo '['$LOGTIME'] Network Problem. Do nothing.' + echo '['$LOGTIME'] Network Problem. Do nothing.' >> $LOGFILE fi fi