Skip to content

Instantly share code, notes, and snippets.

@xi4oh4o
Created December 13, 2012 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xi4oh4o/4276210 to your computer and use it in GitHub Desktop.
Save xi4oh4o/4276210 to your computer and use it in GitHub Desktop.
find fast server for mac
#/bin/bash
#By LordSimon
#Modify xi4oh4o
#ping -c 1 ssh.sshcenter.info
for i in $(seq 21) #will 21 modify you server number count
do
echo "s$i.usassh.com" >> server.list #modify s$i.usassh.com to you server hostname
done
export Local_Result=""
export fastest="999999999"
export fastest_server="NO_SERVER!"
for server in `cat ./server.list`
do
echo "Ping: $server"
Local_Result=`ping -c 1 -W 1 $server|grep 'round-trip min/avg/max/stddev ='`
echo $Local_Result
#get avg value
current_avg=`echo "$Local_Result"|awk -F/ '{print $5}'`
if [ "$current_avg" = "" ];then current_avg=$fastest;fi
if [ `echo "$current_avg<$fastest"|bc` = "1" ]
then
fastest="$current_avg"
fastest_server="$server"
fi
echo "===================="
echo "current fastest:$fastest_server [$fastest]"
echo "===================="
done
echo "Fastest Server: $fastest_server"
echo "avg:$fastest"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment