I want to download OpenBSD with FTP with a script, and I want to download it from a server that is near me. So I want to choose a mirror that has low "ping latency". I wrote a little script, that works just fine (only tested under bash/Linux):
LATESTRELVER=`curl -s 'www.openbsd.org' | fgrep 'The current release is ' | sed 's/OpenBSD /\n/' | sed 's/<\/a>/\n/' | grep "^[0-9]" | head -1`
FASTESTSRV=`curl -s "http://www.openbsd.org/ftp.html#ftp" | fgrep '<a href="ftp://' | sed 's/"ftp:\/\//\n/' | cut -d "/" -f1 | fgrep -v '<a href=' | while read MIRRORSRVS; do ping -c 1 -w 1 $MIRRORSRVS 2>/dev/null | fgrep ' time=' | sed 's/ time=/\n/' | grep ' ms' | sed 's/ ms$/ /' | sed 's/\./ |/' | cut -d "|" -f1 | tr -d '\n'; if [ $? -eq 0 ]; then echo "$MIRRORSRVS"; fi; done | grep "^[0-9]" | sort -un | head -1 | awk '{print $2}'`
LATESTRELVERSHORT=`echo $LATESTRELVER | sed 's/\.//g'`
# NEEDEDARCH=i386
NEEDEDARCH=amd64
wget "$FASTESTSRV/pub/OpenBSD/$LATESTRELVER/$NEEDEDARCH/install$LATESTRELVERSHORT.iso" -O "install$LATESTRELVERSHORT-$NEEDEDARCH.iso"
Q: can someone write this script in Perl? :P (with a smaller, nicer code?)
The main purpose of this script to e.g.: not use foreign country's bandwidth.
tar! – Caleb May 26 '11 at 20:03