feat(find CDN ip): 增加计算排序方法

pull/534/merge
mack-a 2020-07-28 14:47:22 +08:00
parent 6e24b3560f
commit 6422402bf3
1 changed files with 12 additions and 6 deletions

View File

@ -5,7 +5,11 @@ timeout=1000
echoType='echo -e' echoType='echo -e'
trap 'onCtrlC' INT trap 'onCtrlC' INT
function onCtrlC () { function onCtrlC () {
echo 'Ctrl+C is captured' echoContent yellow '计算中'
# 排序计算
echoContent red "排序规则为:先按照丢包率>波动>平均延迟"
echoContent red "依次展示为 ip 丢包率 最小延迟 平均延迟 最大延迟 波动"
cat /tmp/ping.log|sort -t ' ' -k 2n -k 6n -k 4n
exit; exit;
} }
@ -46,21 +50,23 @@ pingTool(){
pingResult=`ping -c ${num} -W ${timeout} ${ip[$i]}` pingResult=`ping -c ${num} -W ${timeout} ${ip[$i]}`
packetLoss=`echo ${pingResult}|awk -F "[%]" '{print $1}'|awk -F "[p][a][c][k][e][t][s][ ][r][e][c][e][i][v][e][d][,][ ]" '{print $2}'` packetLoss=`echo ${pingResult}|awk -F "[%]" '{print $1}'|awk -F "[p][a][c][k][e][t][s][ ][r][e][c][e][i][v][e][d][,][ ]" '{print $2}'`
roundTrip=`echo ${pingResult}|awk -F "[r][o][u][n][d][-][t][r][i][p]" '{print $2}'|awk '{print $3}'` roundTrip=`echo ${pingResult}|awk -F "[r][o][u][n][d][-][t][r][i][p]" '{print $2}'|awk '{print $3}'|awk -F "[/]" '{print $1"."$2"."$3"."$4}'|awk -F "[/]" '{print $1$2$3$4}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}'`
## |awk -F "[/]" '{print $1$2$3}'|awk -F "[.]" '{print $1" "$3" "$5" "$7}'
echo ${roundTrip}
if [[ -z ${roundTrip} ]] if [[ -z ${roundTrip} ]]
then then
roundTrip="无" roundTrip="无"
fi fi
echo "ip: ${ip[$i]}, 丢包率: ${packetLoss}%, 最小/平均/最大/波动: ${roundTrip}" >> /tmp/ping.log echo "ip:${ip[$i]},丢包率:${packetLoss}%,最小/平均/最大/波动:${roundTrip}"
echo "${ip[$i]} ${packetLoss} ${roundTrip}" >> /tmp/ping.log
done done
} }
init(){ init(){
echoContent red "=============================================" echoContent red "============================================="
echoContent green "1.联通" echoContent green "1.联通"
echoContent green "2.移动" echoContent green "2.电信"
echoContent green "3.电信" echoContent green "3.移动"
echoContent yellow "请选择:" echoContent yellow "请选择:"
echoContent red "=============================================" echoContent red "============================================="
read selectType read selectType