[RndTbl] *sigh* I wish there was a better way...

Adam Thompson athompso at athompso.net
Tue Mar 10 13:53:38 CDT 2015


To find the closest and/or fastest CentOS mirror, a function which is 
sadly lacking from CentOS (at least as of v6), this is what I just 
hacked together.  Documenting it here for posterity.
(If you wanted to sort by RTT instead of hopcount, you could either 
reverse the order of i & t in the END block of the awk script, or figure 
out sort(1)'s ridiculous -k option.)

#!/bin/sh
printf 'Hops\tPing\tHost\n'
for h in $(
     lynx -listonly -nonumbers -dump 
http://isoredirect.centos.org/centos/6/isos/x86_64/ |
     egrep '^https?://' |
     sed -e 's#^https*://\([^/]*\)/.*$#\1#'
); do
     mtr -c 1 -r $h | awk -v h=$h 'BEGIN {i=0;t=0}
/^ *[0-9]*\./ {i++; t=$5}
END {print i,t,h}' &
done | sort -n | head -10
wait



More information about the Roundtable mailing list