Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

closed as off topic by xenoterracide May 28 '11 at 11:44

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
ping measures latency, not throughput. Thus it is useless for comparing ftp servers. –  Kim May 26 '11 at 17:35
    
that's fully true, but the lower the ping the nearer the server is. I don't want to use servers what are too far away...on a foreign land –  LanceBaynes May 26 '11 at 18:06
    
Trust us on this one, you don't care where an ftp server is if it gives you better throughput. The only exception would be if you pay for bandwidth differently depending on where it's coming from, but at your level of the networking world that is probably an irrelevant factor. Throughput is the metric you want to use, not ping times! If this was about something other than FTP, you could make a case for round trip times, but ftp is about file transfer. If all yours files are tiny you should reconsider not having used tar! –  Caleb May 26 '11 at 20:03
    
"Q: can someone write this script in Perl? :P (with a smaller, nicer code?)" this is not ontopic and not a real question. –  xenoterracide May 28 '11 at 11:44
    
It would be closed on stackoverflow even because you're asking someone to do your work for you. If you were to put some effort into writing it in perl, and got stuck, then you could ask this on stackoverlow. –  xenoterracide May 28 '11 at 11:45

1 Answer 1

The easiest way to select some suitable mirrors is with netselect. You can use the -s 3 option to tell it to pick the 3 best servers.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.