k2定时脚本
root@K2:~# crontab -l 0 1 * * * /etc/shadowsocks/update.sh >> /var/log/shadowsocks_watchdog.log 2>&1 */10 * * * * /etc/shadowsocks/checknet.sh >> /var/log/shadowsocks_watchdog.log 2>&1 0 1 * * 7 echo "" > /var/log/shadowsocks_watchdog.log
更新ip地址
root@K2:~# cat /etc/shadowsocks/update.sh wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ \ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /etc/chinadns_chnroute.txt \ && /etc/init.d/shadowsocks restart && /etc/init.d/chinadns restart root@K2:~#
检查网络状态,发现有问题就重启 root@K2:~# cat /etc/shadowsocks/checknet.sh #!/bin/sh LOGTIME=$(date "+%Y-%m-%d %H:%M:%S") wget --spider --quiet --tries=1 --timeout=10 www.google.co.jp if [ "$?" == "0" ]; then echo '['$LOGTIME'] No Problem.' exit 0 else wget --spider --quiet --tries=1 --timeout=10 www.baidu.com if [ "$?" == "0" ]; then echo '['$LOGTIME'] Problem decteted, restarting shadowsocks.' /etc/init.d/shadowsocks restart /etc/init.d/chinadns restart else echo '['$LOGTIME'] Network Problem. Do nothing.' fi fi root@K2:~#