#! /usr/bin/perl -w use strict ; my $MIR_LIST = '/home/apmirror/mirrors/mirrors.list' ; my $DEF_STATE = '/home/apmirror/mirrors/mirmon/prod/mstat.txt' ; my $DATE_FILE = '/www/www.apache.org/dist/zzz/time.txt' ; my $maxtime = 48*60*60 ; my $mingood = 100 ; my $prog = substr($0,rindex($0,'/')+1) ; my $Usage = < mirors ; default : $mingood default state-file : $DEF_STATE default out-file : STDOUT USAGE sub Usage { die "$_[0]$Usage" ; } sub Error { die "$prog: $_[0]\n" ; } sub Warn { warn "$prog: $_[0]\n" ; } # usage: &GetOptions(ARG,ARG,..) defines $opt_ID as 1 or user spec'ed value # usage: &GetOptions(\%opt,ARG,ARG,..) defines $opt{ID} as 1 or user value # ARG = 'ID' | 'ID=SPC' | 'ID:SPC' for no-arg, required-arg or optional-arg # ID = perl identifier # SPC = i|f|s for integer, fixedpoint real or string argument use Getopt::Long ; Getopt::Long::config('no_ignore_case') ; my %opt = () ; Usage('') unless GetOptions ( \%opt, qw(v q d m=i) ) ; Usage("Arg count\n") unless 0 <= @ARGV and @ARGV <= 2 ; my $STATE = shift || $DEF_STATE ; my $OUT = shift ; $mingood = $opt{m} if defined $opt{m} ; my $TMP ; if ( defined $OUT ) { $TMP = "$OUT.tmp" ; open TMP, ">$TMP" or Error "can't write $TMP ($!)" ; select TMP ; } my %uptodate = () ; my $goodmirrors = 0 ; open DATE, $DATE_FILE or Error "can't open $DATE_FILE ($!)" ; my $date = ; close DATE ; chomp $date ; my $worstdate = $date - $maxtime ; open STATE, $STATE or Error "can't open $STATE ($!)" ; my @lines = ; close STATE ; for my $line ( @lines ) { chomp $line ; my @splitline = split ' ', $line ; my $mirrordate = $splitline [ 1 ] ; if ( $mirrordate eq 'undef' or $splitline[2] ne 'ok' ) { $mirrordate = 0 ; } $uptodate { $splitline [ 0 ] } = $mirrordate ; $goodmirrors ++ if $mirrordate > $worstdate ; } Error "not enough good mirrors ($goodmirrors<$mingood)" if $goodmirrors < $mingood ; open MIR_LIST, $MIR_LIST or Error "can't open $MIR_LIST ($!)" ; @lines = ; close MIR_LIST ; for my $line ( @lines ) { chomp $line ; next if $line =~ /^\s*$/ ; next if $line =~ /^#/ ; my @sl = split ' ', $line ; my $url = $sl [ 2 ] ; my $num = $uptodate { $url } || 0 ; printf "%s %s %s %d\n", $sl[0], $sl[1], $sl[2], $num ; } if ( $TMP ) { close TMP ; rename $TMP, $OUT or Error "can't rename $TMP $OUT ($!)" ; }