写了一个脚本实现我需要的能力
#!/bin/sh
check_node_availability() {
local url=$1
response=$(curl -s -I "$url")
if echo "$response" | grep -q "200 OK"; then
echo "$url is accessible"
return 0
else
echo "$url is not accessible"
return 1
fi
}
check_url() {
success_count=0
for _ in 1 2 3
do
if check_node_availability "
https://github.com"; then
success_count=$((success_count + 1))
fi
wait
sleep 3
done
return "$success_count"
}
while :
do
# 只在美国和英国节点间切换 tail -10
for node_id in `uci export passwall | grep 'config nodes' | tail -10 | awk '{print $3}'`; do
eval "i=${node_id}"
uci delete passwall.@global[0].tcp_node
wait
uci add_list passwall.@global[0].tcp_node=${i}
uci show passwall.@global[0].tcp_node
wait
uci commit passwall
wait
/etc/init.d/passwall restart
wait
sleep 10
while :
do
success_count=$(check_url)
if [ "$success_count" -ne 3 ]; then
echo "Switching to another node..."
break
else
sleep 600
fi
done
done
done