#!/usr/bin/perl -s use strict; use warnings; ## Scott Wiersdorf ## Created: Thu Jan 11 08:54:03 MST 2007 ## $Id: procsum,v 1.5 2007/01/11 18:06:34 scott Exp $ ## procmail log reports for given date use HTTP::Date qw(str2time); use Time::Local qw(timelocal); no strict 'refs'; our $today ||= ${-today}; our $nohead ||= ${-nohead}; our $version ||= ${-version}; use strict 'refs'; our $VERSION = q!0.50 ($Date: 2007/01/11 18:06:34 $)!; if( $version ) { my $ver = $VERSION; $ver =~ s/\$Date: /released /; $ver =~ s/ \$//; print "This is procsum, version $ver\n"; exit; } my ($day, $month, $year) = (localtime( $today ? time : time-86400 ))[3..5]; $month += 1; $year += 1900; my $start_time = timelocal(0, 0, 0, $day, ($month-1), $year); my $end_time = timelocal(59, 59, 23, $day, ($month-1), $year); for my $file ( @ARGV ) { unless( $nohead ) { print "Log summary for $file\n"; print "(" . scalar localtime($start_time) . " to " . scalar localtime($end_time) . "):\n\n"; } my $state = 0; open FILE, "<", $file or next; while( ) { if( /^From .* (\w{3}\s+\w{3}\s+\d{1,2}\s+[\d:]+\s+\d{4})/ ) { my $mtime = str2time($1); next if $mtime < $start_time; last if $mtime > $end_time; $state = 1; } print if $state; } close FILE; } exit; __END__ =head1 NAME procsum - procmail log summary =head1 SYNOPSIS procsum [--today] [--nohead] procmail.log =head1 DESCRIPTION B prints yesterday's entries in a procmail log--sort of a daily digest of a procmail log. With the B<--today> option you get today's log entries. That's all it does. B prints out a brief header, which can be suppressed with the B<--nohead> option. =head1 PURPOSE I got tired of logging into my server to read procmail logs after tweaking my spam rules, so I wrote B to grok yesterday's procmail log for me and send me an email of the summary. =head1 INSTALLATION Copy B to anywhere you want it on your server and make sure it's executable (F). To run B from cron, you might try something like this: 10 4 * * * /usr/local/sbin/procsum $HOME/procmail.log | mail -s "log summary" joe This will send the log summary to user 'joe'. =head1 AUTHOR Scott Wiersdorf, Escott@perlcode.orgE =head1 COPYRIGHT Copyright (c) 2007 Scott Wiersdorf. All rights reserved. =head1 LICENSE B is released under the Perl Artistic License. See L. =head1 SEE ALSO L =cut