我的理解:
1.先定义4个节点
2.使用ping节点,获取响应时间
3.依次保存到ping.pl结果中
4.再对ping.pl结果排序,取最时间最短的节点地址,如果不存在,默认就使用HK2节点
5.根据结果拼接 download地址
6.删除ping.pl结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #自动选择下载节点
CN='125.88.182.172'
HK='download.bt.cn'
HK2='103.224.251.67'
US='128.1.164.196'
CN_PING=`ping -c 1 -w 1 $CN|grep time=|awk '{print $7}'|sed "s/time=//"`
HK_PING=`ping -c 1 -w 1 $HK|grep time=|awk '{print $7}'|sed "s/time=//"`
HK2_PING=`ping -c 1 -w 1 $HK2|grep time=|awk '{print $7}'|sed "s/time=//"`
US_PING=`ping -c 1 -w 1 $US|grep time=|awk '{print $7}'|sed "s/time=//"`
echo "$HK_PING $HK" > ping.pl
echo "$HK2_PING $HK2" >> ping.pl
echo "$US_PING $US" >> ping.pl
echo "$CN_PING $CN" >> ping.pl
nodeAddr=`sort -V ping.pl|sed -n '1p'|awk '{print $2}'`
if [ "$nodeAddr" == "" ];then
nodeAddr=$HK2
fi
download_Url=http://$nodeAddr:5880
rm -f ping.pl |
----------------------------------------------
知识点:
1.awk
2.sed
3.sort