Quick and dirty Ubuntu mirror chooser

Well, the default Ubuntu security mirror was being super unresponsive today, so I wanted to use, gasp, a mirror. apt-spy and netselect aren’t really ubuntu-ready out of the box, so I wrote this quick bash script.

Just grab the mirrors list from the Ubuntu Archive mirrors list, and put it into a file called mirrors.txt, like this:

http://mirror.cs.umn.edu/ubuntu/
http://lug.mtu.edu/ubuntu/
http://mirror.clarkson.edu/pub/distributions/ubuntu/
http://ubuntu.mirrors.tds.net/ubuntu/
http://www.opensourcemirrors.org/ubuntu/
http://ftp.ale.org/pub/mirrors/ubuntu/
http://ubuntu.secs.oakland.edu/
http://mirror.mcs.anl.gov/pub/ubuntu/
http://mirrors.cat.pdx.edu/ubuntu/
http://ubuntu.cs.utah.edu/ubuntu/
http://ftp.ussg.iu.edu/linux/ubuntu/
http://mirrors.xmission.com/ubuntu/
http://ftp.osuosl.org/pub/ubuntu/
http://mirrors.cs.wmich.edu/ubuntu/

Read through the super-short script and you’ll figure it out.

#!/bin/bash

mirrors=`cat mirrors.txt`
results="results.txt"
target="ls-lR.gz"

for mirror in $mirrors
do
echo "Testing $mirror ..."
curl -s $mirror/$target -o $target \\
   -w 'Got speed: %{speed_download} from %{url_effective}\\n' \\
   --connect-timeout 3 | tee -a $results
rm -f $target
done
del.icio.us:Quick and dirty Ubuntu mirror chooser digg:Quick and dirty Ubuntu mirror chooser reddit:Quick and dirty Ubuntu mirror chooser gifttagging:Quick and dirty Ubuntu mirror chooser

About this entry