#!/usr/bin/perl
# bad-links-www.pl

sub usage {
  die "usage: bad-links-www.pl -d <date> [-s] [-v]

<date>	is an 8 digit date of the form yyyymmdd, e.g. 19980221
-s	send error reports to file owners
-v	verbose
";
}

$| = 1;					# unbuffered output
unshift(@INC, '/opt/ACISweb/lib');
require 'webconfig.pm';
&webconfig'getconfig('', \%stype,
	\@sname, \%lname, \%alias, \%droot, \%hostlist, \$poolhosts);

require 'getopts.pl';
&Getopts('d:sv');
print "\nparse error files to create web error reports\n";
if ($opt_s) {
  print "then mail the error reports to the file owners\n";
} else {
  print "but do not mail the error reports\n";
}
$rpt='/www/data/httpd/reports';
$date=$opt_d;
&usage unless $date;
$GBIN='/opt/ACISweb/bin/getstats';
$BADLINKS="$GBIN/bad-links.pl";
die "can't find $BADLINKS: $!\n" unless -x $BADLINKS;

foreach $whost (@sname) {
  next unless ($whost eq 'www') || ($stype{$whost} eq 'virtual');
  local($infilnam).="$rpt/$whost/$date.error.list";
  local($command) = "$BADLINKS $lname{$whost} $droot{$whost}";
  $command.=" -s" if $opt_s;		# send web error reports via email
  $command.=" <$infilnam  >$rpt/$whost/$date.error.rpt";
  system($command) if -r $infilnam;
}
