Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于检测ss状态并自动重新连接的一点思路。 #19

Open
Edelwiess opened this issue Dec 10, 2017 · 3 comments
Open

关于检测ss状态并自动重新连接的一点思路。 #19

Edelwiess opened this issue Dec 10, 2017 · 3 comments

Comments

@Edelwiess
Copy link

  1. 判断ss状态的文件是:
    /jffs/koolshare/scripts/ss_status.sh
    #===================================================================
    #!/bin/sh

alias echo_date1='echo $(date +%Y年%m月%d日\ %X)'
export KSROOT=/jffs/koolshare
source $KSROOT/scripts/base.sh
eval dbus export ss_
date=echo_date1
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")

get_china_status(){
wget -4 --spider --quiet --tries=2 --timeout=2 www.baidu.com
if [ "$?" == "0" ]; then
log2='国内链接 【'$LOGTIME'】 ✓'
else
log2='国内链接 【'$LOGTIME'】 X'
fi
}

get_foreign_status(){
wget -4 --spider --quiet --tries=2 --timeout=2 www.google.com.tw
if [ "$?" == "0" ]; then
log1='国外链接 【'$LOGTIME'】 ✓'
else
log1='国外链接 【'$LOGTIME'】 X'
fi
}

get_china_status
get_foreign_status

http_response "$log1@@$log2"

#==================================================================
需要实现的操作是如果国外连接状态中有X就去执行
/jffs/koolshare/scripts# ss_config.sh start
个人以为这个检测每2分钟做一次就好。
但是我也不会写sh脚本,还是需要有专业人员帮助一下,我只能提供一个思路。

@Edelwiess
Copy link
Author

自力更生写了一个脚本
使用时:sh xxxx.sh

#!/bin/sh

alias echo_date1='echo $(date +%Y年%m月%d日\ %X)'
export KSROOT=/jffs/koolshare
source $KSROOT/scripts/base.sh
eval dbus export ss_
date=echo_date1
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")

get_china_status(){
wget -4 --spider --quiet --tries=2 --timeout=2 www.baidu.com
if [ "$?" == "0" ]; then
log2='【'$LOGTIME'】 ping www.baidu.com succed'
else
log2='国内链接 【'$LOGTIME'】 X'
fi
}

get_foreign_status(){
wget -4 --spider --quiet --tries=2 --timeout=2 www.google.com.tw
if [ "$?" == "0" ]; then
log1='【'$LOGTIME'】 ping www.googel.com.tw succed'
log3='No need to restart ss'
else
log1='【'$LOGTIME'】 ping www.googel.com.tw failed, Restarting shadowsocks'
sh /jffs/koolshare/scripts/ss_config.sh start
log3='ss restarted'
fi
}

get_china_status
get_foreign_status

echo $log1
echo $log2
echo $log3

@Edelwiess
Copy link
Author

#!/bin/sh

alias echo_date1='echo $(date +%Y年%m月%d日\ %X)'
export KSROOT=/jffs/koolshare
source $KSROOT/scripts/base.sh
eval dbus export ss_
date=echo_date1
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")

get_china_status(){
wget -4 --spider --quiet --tries=2 --timeout=2 www.baidu.com
if [ "$?" == "0" ]; then
log2='【'$LOGTIME'】 Testing www.baidu.com. Succed!'
else
log2='【'$LOGTIME'】 Testing www.baidu.com. Failed! Please check WAN settings.'
fi
}

get_foreign_status(){
wget -4 --spider --quiet --tries=2 --timeout=2 www.google.com.tw
if [ "$?" == "0" ]; then
log1='【'$LOGTIME'】 Testing www.googel.com.tw. Succed!'
log3='No need to restart shadowsocks.'
else
log1='【'$LOGTIME'】 Testing www.googel.com.tw. failed! Restarting shadowsocks.'
sh /jffs/koolshare/scripts/ss_config.sh start
log3='Shadowsocks restarted.'
fi
}

get_china_status
get_foreign_status

echo $log1
echo $log2
echo $log3

@Edelwiess
Copy link
Author

我写好了一个能用的了
https://github.com/Edelwiess/ss-autorestart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant