-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_speedtest.sh
executable file
·120 lines (67 loc) · 2.53 KB
/
start_speedtest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# 第一部分脚本的作用,利用expect连接上本地的ubuntu,然后切换到~目录下,执行stairspeedtest
#输出的结果自动放到文件夹下的/results下面,生成一副图和log,用于后续的python脚本分析结果
#在第二部分的expect中,连接openwrt,通过edit_proxy_cfg.py这个模块,获取和修改节点配置信息
#最后uci commit,init.t重载passwall服务
#本脚本作为最主要的,需要在计划任务中配合passwall的节点更新,记得设置好
link="xxxxxx" #在这里面填入你想自动测速选择的订阅链接,默认只能一个机场订阅
group_name="xxxx" #这里填你想给测速时生成的组名称,无关紧要
# 这里我加一个让openwrt先更新订阅,然后关闭passwall,最后重启passwall
/usr/bin/expect <<-EOF
set timeout 10
spawn ssh [email protected]
expect {
"password*" {send "password\n";exp_continue} #这里填openwrt机器的密码,
"yes/no*" {send "yes\n"}
}
expect "OpenWrt*"
set timeout 20
send "lua \/usr\/share\/passwall\/subscribe.lua start\n"
expect "null to execute the next command"
send "\/etc\/init.d\/passwall stop\n"
expect "null to execute the next command"
EOF
#第二部分开始测速和数据处理
/usr/bin/expect <<-EOF
set timeout 10
spawn ssh [email protected]
expect {
"password*" {send "password\n";exp_continue} #这里填用来测速的机器的密码,因为自动测速不能放在openwrt上完成
"yes/no*" {send "yes\n"}
}
expect "Ubuntu*"
send "cd stairspeedtest\/\n"
send ".\/stairspeedtest\n"
expect "Link:*"
send "$link\n"
expect "Custom Group Name:\n"
set timeout 1800
send "$group_name\n"
expect eof
EOF
cd /home/username #这里填ubuntu机器的用户名,关键的测速文件auto_proxy以及stairspeed test会在这个目录下
python auto_proxy.py
# 解析上面获得的results目录下的log文件的脚本
#然后将处理完的文件传给openwrt,进行节点获取和修改
/usr/bin/expect <<-EOF
set timeout 10
spawn ssh [email protected]
expect {
"password*" {send "password\n";exp_continue} #同上面 openwrt密码
"yes/no*" {send "yes\n"}
}
expect "OpenWrt*"
send "scp [email protected]:~\/node_result.txt .\n" #ubuntu用户名
expect {
"password*" {send "password\n";exp_continue} #右边的password是ubuntu密码
"yes/no*" {send "yes\n"}
}
expect "100%*"
set timeout 50
send "python edit_proxy_cfg.py\n"
expect "nothing else"
set timeout 30
send "\/etc\/init.d\/passwall start\n"
expect "nothing else"
EOF
exit