Created
August 8, 2017 10:13
-
-
Save libook/154d30593b3f92e91df874503b870727 to your computer and use it in GitHub Desktop.
Finding best server with pinging a list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# The first argument is the list file. | |
count=4 | |
all='' | |
echo "Start to ping all the servers..." | |
for ip in `cat $1` | |
do | |
avg="`ping -t ${count} ${ip}`" | |
#echo "${avg}" | |
unknown_host=`echo "${avg}"|grep -i avg` | |
if [[ -z "${unknown_host}" ]] | |
then | |
avg="unknown host ${ip}" | |
all+="${avg}ms ${ip}\n" | |
else | |
avg="`echo "${avg}"|grep avg|cut -d "=" -f2|cut -d "/" -f2|cut -d "." -f1`" | |
# echo "${avg}" | |
all+="${avg}ms ${ip}\n" | |
fi | |
echo ${avg} ${ip} | |
done | |
echo "" | |
echo "The rank list:" | |
echo -e "$all"|grep -v "^$"|sort -k1n|grep -n "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment