#!/usr/bin/perl # Id: $Id: qlogs4awstats,v 1.2 2004/01/14 11:13:42 hutch Exp $ # Log: $Log: qlogs4awstats,v $ # Log: Revision 1.2 2004/01/14 11:13:42 hutch # Log: tidied it up and added some comment # Log: # Log: Revision 1.1 2004/01/14 11:01:48 hutch # Log: added to cvs # Log: # # qlogs4awstats # grab dates of files, decide which ones to use, run it through the massage # and output. # Pipe into awstats/tools/maillogconvert.pl # LogFile="/usr/local/bin/qlogs4awstats 3600 | " # set the parameter to the same time interval as the cron, in seconds # tested with Awstats 5.9 chdir("/var/log/qmail"); my $taiprog = "/usr/local/bin/tai64nlocal"; # pulled from the awstats cvs, handles tai64nlocal format my $mailconvprog = "/usr/local/awstats/tools/maillogconvert-1.20.pl standard"; # this gets them in the right order my @Logs = `ls -tr`; my @Newlogs; my ($log); my $now = time(); # default 1 day my $interval = 60*60*24; # check to see if there is a param if(@ARGV) { $interval = int($ARGV[0]); } foreach $log(@Logs) { chomp($log); if( ($log =~ /\@.*\.s/) or ($log =~ /^current/) ) { my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($log); if ( $mtime > ($now-$interval) ) { push(@Newlogs, $log); } } } my $logtot = $#Newlogs + 1; if( $logtot > 0 ) { foreach $log (@Newlogs) { @Lines = `cat $log | $taiprog | $mailconvprog `; foreach $line(@Lines) { print $line; } } } exit; ## eof ##