#!/usr/bin/perl # weekly-reports.pl # this job runs after the web logs have been orbited and # copied to the central repository # to send error reports by mail, this must run on a host that contains # all users in the /etc/passwd file if ($#ARGV > -1) { die "usage: weekly-reports.pl\n"; } $| = 1; # unbuffered output umask(027); # files not world readable $LS='/usr/bin/ls'; $WC='/usr/ucb/wc'; $PRG='/www/data/httpd/pl'; $REP='/www/data/httpd/reports'; $LOG='/www/data/httpd/log/fu'; $SEC='/www/data/httpd/log/sec'; $GZIP='/usr/local/bin/gzip'; $ZCAT='/usr/local/bin/zcat'; $weekfile="$PRG/thisweek"; die "Unable to open $weekfile because $!\n" unless open(DATEFILE, "<$weekfile"); chop($thiswk=); # report date in the form "Sep 13, 1997" chop($thisrep=); # report date in the form "19970913" close(DATEFILE); # for these auxiliary web servers we concatenate the daily logs # into weekly log files, but don't generate reports if (&concatenate_httpd('alhan', 'gutentag', 'kalimera')) { print "some log files are incomplete\n"; } # now process the logs from our primary web servers if (&concatenate_httpd('jonapot', 'kwaziwai')) { print "getstats not executed because some log files are incomplete\n"; } else { # *** create the reports for the main server *** print "weekly reports will be created for $thiswk ($thisrep)\n\n"; system("$PRG/run-gs-std.pl $thisrep"); # update the list of dates on the web page system("$PRG/insert-date.pl $weekfile $REP/weeklist.sel"); # add this week to the top of weeklist for the showrep cgi program die "Can't create $REP/weeklist.new: $!\n" unless open(NEWLIS, ">$REP/weeklist.new"); die "Can't open $REP/weeklist: $!\n" unless open(OLDLIS, "<$REP/weeklist"); print NEWLIS "$thisrep\n"; print NEWLIS ; # copy the rest of the file close(NEWLIS); close(OLDLIS); die "Can't rename $REP/weeklist.new: $!\n" unless rename("$REP/weeklist.new", "$REP/weeklist"); print " $thisrep added to the top of weeklist\n\n"; } # *** create the reports for the secure server *** if (&concatenate_httpsd('howsit')) { print "getstats for www1 not executed because log files are incomplete\n"; } else { print "www1 reports will be created for $thiswk ($thisrep)\n\n"; system("$PRG/run-gs-sec.pl $thisrep"); } $command="$PRG/bad-links.pl -s <$REP/columbia/$thisrep.error.list >$REP/columbia/$thisrep.error.rpt"; print "create and mail the individual error reports:\n$command\n\n"; system($command); ############################################################ sub concatenate_httpd { # uncompress and concatenate daily logs to create weekly files local(@hostlist) = @_; local($status) = ''; $accfil="httpd.access.$thisrep"; $errfil="httpd.error.$thisrep"; for $host (@hostlist) { local($dayfiles); chdir("$LOG/$host"); if (system("$ZCAT prev/httpd.error.*.day.gz | $GZIP >$errfil.gz")) { print "can't create $host/$errfil.gz\n"; $status=1; next; } print " created $host/$errfil.gz\n"; chop($dayfiles=`$LS prev/httpd.access.*.day.gz | $WC -l`); if ($dayfiles == 7) { if (system("$ZCAT prev/httpd.access.*.day.gz | $GZIP >$accfil.gz")) { print "can't create $host/$accfil.gz\n"; $status=1; next; } print " created $host/$accfil.gz\n"; # find leftover wrk files $wrkfiles=`$LS prev/httpd.access.*.day.wrk.gz 2>&1`; if (($wrkfiles !~ /not found/) && ($wrkfiles !~ /No such file/)) { print " daily wrk files to be deleted:\n$wrkfiles"; $status=1; } } else { print " unable to create $host/$accfil\n"; print " need 7 daily logs for host $host\n"; system("$LS -l prev/httpd.access.*.day.*"); $status=1 if (($host eq 'jonapot') || ($host eq 'kwaziwai')); } } return $status; } # concatenate_httpd sub concatenate_httpsd { # uncompress and concatenate secure daily logs to create weekly files local(@hostlist) = @_; local($status) = ''; $accfil="httpsd.access.$thisrep"; $errfil="httpsd.error.$thisrep"; $misfil="httpsd.misc.$thisrep"; for $host (@hostlist) { local($dayfiles); chdir("$SEC/$host"); chop($dayfiles=`$LS prev/httpsd.access.*.day.gz | $WC -l`); if ($dayfiles == 7) { system("$ZCAT prev/httpsd.access.*.day.gz | $GZIP >$accfil.gz"); print " created $host/$accfil.gz\n"; } else { print " unable to create $host/$accfil\n"; print " need 7 daily logs for host $host\n"; system("$LS -l prev/httpsd.access.*.day.*"); $status=1; } system("$ZCAT prev/httpsd.error.*.day.gz | $GZIP >$errfil.gz"); print " created $host/$errfil.gz\n"; system("$ZCAT prev/httpsd.misc.*.day.gz | $GZIP >$misfil.gz"); print " created $host/$misfil.gz\n"; return $status; } } # concatenate_httpsd