[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: mirror up-to-dateness report



alexlist@sbox.tu-graz.ac.at said:
> What would you think about a script that checks the
> connectivity to a given set of "closest" mirrors based on the "Timezone" 
> or so and reports the "fastest"  mirror available? 

here's a perl script i wrote that uses the 'ping' program to find the
'distance' to a mirror, sorting the sites from closest to farthest.
you need to plug in the list of mirrors, although the program could be
easily modified to use a list from standard input.  (perhaps the
mirrors.txt file could be made more easily machine-readable?)

john

-CUT HERE---------------------------------------------------------------------
#!/usr/bin/perl -w

use strict

@sites = split(/\n/, <<EOF);
aij.st.hmc.edu
ftp.cdrom.com
ftp.fuller.edu
debian.med.miami.edu
ftp.debian.org
ftp-nog.rutgers.edu
sun10.sep.bnl.gov
llug2.sep.bnl.gov
chaos.xtn.net
uiarchive.uiuc.edu
ftp.caldera.com
debian.crosslink.net
EOF

my $distance;
my %sites = ();
my $site;

for $site (@sites) {
  if (($distance = &Ping($site)) > 0) {
    $sites{$site} = $distance;
  }
}

for $site (sort { $sites{$a} <=> $sites{$b} } keys %sites) {
  printf("%8d $site\n", $sites{$site});
}

######################################################################

sub Ping {
  my ($host) = @_;
  local *PING;
  my $distance = 0;

  open(PING, "ping -n -q -c 1 $host |")
    || die "Couldn't open pipe to `ping': $!\n";

  while (<PING>) {
    chop;

    # round-trip min/avg/max = 1.0/1.0/1.0 ms

    if (m!^round-trip min/avg/max = ([\d\.]+)/([\d\.]+)/([\d\.]+) ms!) {
      $distance = int($1);
    }
  }

  close PING;

  return $distance;
}
-CUT HERE---------------------------------------------------------------------


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-REQUEST@lists.debian.org . Trouble? e-mail to Bruce@Pixar.com


Reply to: