#!/usr/bin/perl # /usr/local/etc/copy-weblogs.pl # # copies the daily httpd logs to the central repository and removes them # runs as root so it can remove the old logs # runs daily on the regular (non-secure) web server hosts, after the # logs have been rotated chop($DA=`which date`); die("can't find date program\n") if $DA =~ /^no /; if ($#ARGV > 0) { die "usage: copy-log-files [date]\n"; } elsif ($#ARGV == 0) { $date=$ARGV[0]; } else { chop($date=`$DA +19%y%m%d`); } $LOG='/www/data/httpd/log/fu'; $ruser='beecher'; # su to beecher so we can write to toaster $verbose=''; chop($ECHO=`which echo`); die("can't find echo\n") if $ECHO =~ /^no /; chop($CP=`which cp`); die("can't find cp\n") if $CP =~ /^no /; chop($RM=`which rm`); die("can't find rm\n") if $RM =~ /^no /; chop($HN=`which hostname`); die("can't find hostname program\n") if $HN =~ /^no /; chop($host=`$HN`); # copy the previous day's log files to the repository # and remove it from the web server host # logs from our primary web servers need to be resolved # using logres, so these are named "wrk" files for $ftype ('access', 'error') { local($yesterlog)="/var/log/cnet/httpd_${ftype}_log.1.gz"; if (($ftype eq 'access') && (($host eq 'jonapot') || ($host eq 'kwaziwai'))) { $cmd="$CP -p $yesterlog $LOG/$host/curr/httpd.$ftype.$date.day.wrk.gz"; } else { $cmd="$CP -p $yesterlog $LOG/$host/curr/httpd.$ftype.$date.day.gz"; } print "--> $cmd\n" if $verbose; if (!system("$ECHO \"$cmd\" | su $ruser")) { # copy the log file print "--> $RM $yesterlog\n" if $verbose; system("$RM $yesterlog"); # remove the log file } for $dayz (2, 3) { # look for old files that were not copied $yesterlog="/var/log/cnet/httpd_${ftype}_log.$dayz.gz"; next unless -r $yesterlog; print "found an old log file from $dayz days ago:\n"; $cmd="$CP -p $yesterlog $LOG/$host/curr/httpd.$ftype.$date.day$dayz.gz"; print "--> $cmd\n" if $verbose; if (!system("$ECHO \"$cmd\" | su $ruser")) { # copy the log file print "--> $RM $yesterlog\n" if $verbose; system("$RM $yesterlog"); # remove the log file } } }