[pkg-bioc] CVS %p
Dirk Eddelbuettel
edd at debian.org
Wed Feb 28 02:35:23 CET 2007
On 27 February 2007 at 16:44, Steffen Moeller wrote:
| for i in de us; do ping -c 2 cran.$i.r-project.org -q -W 1|tail -1|
| cut -f2 -d= |cut -f2 -d/; done
| 35.508
| 123.650
|
Below is something similar I once wrote for Debian's mirror package (which I
used to maintain). This is from before we had all those apt tools testing
for bandwidth...
I am not sure how much Perl has changed and what else we'd need to depend
on -- and it needs to read the mirror list from cmdline, or a cran mirror
list, or something...
Dirk
#!/usr/bin/perl
#
# debian-mirrors measure ping time to all mirrors in README.mirrors.txt
#
# downloads README.mirrors.txt from ftp.debian.org (but not if a local file
# is pointed to), runs fping on all Debian mirrors, sorts the result by ping
# time and output the 'n' (default is 20) fastest mirrors.
#
# Written by Dirk Eddelbuettel <edd at debian.org> and released under the GPL
# $Id: debian-mirrors.pl,v 1.9 2001/01/29 04:09:30 edd Exp $
## Yes, Net::FTP is much cooler, but we don't want to depend on libnet-perl
## 'ftp.pl' is provided by the mirror package
unshift( @INC, "/usr/lib/mirror" );
require 'ftp.pl';
#use strict; # doesn't work with ftp.pl, neither does -w
use English;
use File::Basename;
use Getopt::Std;
use IPC::Open2;
use vars qw($opt_h $opt_f $opt_v);
my $filename = "README.mirrors.txt";
my $inputfile = "/tmp/$filename" . "-" . $$;
my $max = 20;
$PROGRAM_NAME =~ s|.*/||; # strip everything before last slash
getopts('hf:n:v') or die("Try `$PROGRAM_NAME -h` for help screen.\n");
if ($opt_h or $#ARGV != -1) {
print "Usage:\n $PROGRAM_NAME [options]\n";
print "Options:\n";
print " -f file\tpoint to local version README.mirrors.txt\n";
print " -n max\tmaximum number of mirrors to show\n";
print " -v\t\tverbose operation\n";
print " -h\t\tshow this help\n";
exit 0;
}
$max = $opt_n if ($opt_n);
print "Max is set to $max\n" if $opt_v;
if ( ! $opt_f ) {
my $hostname = "ftp.debian.org";
my $account = "ftp";
my $password = "user\@debian.org";
my $directory = "/debian";
print "Retrieving ", $filename, " for analysis.\n" if $opt_v;
ftp::debug(1) if $opt_v; # for debugging output
ftp::open($hostname,21,0,1) or die "No ftp connection\n";
ftp::login($account, $password) or die "Couldn't login\n";
ftp::cwd($directory) or die "Cannot cd to $directory\n";
ftp::get($filename, $inputfile, 0) or die "Could not get $filename\n";
ftp::quit();
} else {
die "File $opt_f does not exist.\n" unless -f $opt_f;
$inputfile = $opt_f;
}
print "Measuring ping times to all Debian mirror sites. " if $opt_v;
print "Please be patient.\n" if $opt_v;
open(DATA, $inputfile) or die "Cannot open $filename\n";
open2("PINGOUT", "PINGIN", "fping -ae") or die "Cannot start fping(1)\n";
# Parse the README.mirrors.txt file
my $state = 0;
while (<DATA>) { # parse the file for ftp sites
next if (m/^\s*$/); # skip empty lines
next if (m/---/); # skip separator lines
next if (m/Country/); # skip header line
next if (m/^[A-Z]{2}/); # skip country header among secondaries
next if (m/^Last modi/); # skip trailer
my $mirror = undef;
## the following is really crude code, and my only excuse is that the
## README.mirrors.txt isn't quite as normalised as I'd like it to be ...
if (m/Primary Debian Mirror Sites/) {
$state = 1;
} elsif (m/Secondary mirrors of the Debian archive/) {
$state = 2;
} elsif ($state ne 0) {
if ($state eq 1) { # easy: all sites conform to ftp.XX.debian.org
($mirror) = ($ARG =~ m|(ftp\.\w\w\.debian\.org)|);
## The commented code allows for the secondaries I seem to be getting
## ICMP errors and timeouts. So far now, this will only query our
## primary mirrors. --edd 25 Jan 2001
## } elsif ($state eq 2) { # begins with letters and a dot, and has a / path
## ($mirror) = ($ARG =~ m|(^\S*\.\S*)\s*/|);
}
if (defined($mirror)) {
print "Pinging $mirror \n" if $opt_v;
print PINGIN "$mirror\n";
}
}
}
close(DATA);
close(PINGIN);
unlink($inputfile) unless $opt_f;
open2("SORTOUT", "SORTIN", "sort -n") or die "Cannot start sort(1)\n";
while (<PINGOUT>) {
my ($mirror,$time) = ($ARG =~ m|^(\S*)\s*\((\d+\.?\d*) ms(ec)?\)|);
print "fping reports $time for $mirror\n" if $opt_v;
print SORTIN "$time $mirror\n";
}
close(SORTIN);
close(PINGOUT);
my $i=1;
while (<SORTOUT>) {
print "$ARG";
last if ($i++ == $max);
}
close(SORTOUT);
--
Hell, there are no rules here - we're trying to accomplish something.
-- Thomas A. Edison
More information about the pkg-bioc-devel
mailing list