Skip to content

Instantly share code, notes, and snippets.

@libook
Created August 8, 2017 10:13
Show Gist options
  • Save libook/154d30593b3f92e91df874503b870727 to your computer and use it in GitHub Desktop.
Save libook/154d30593b3f92e91df874503b870727 to your computer and use it in GitHub Desktop.
Finding best server with pinging a list.
#!/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