#!/usr/local/bin/perl -w # Kevin P. Inscoe (kevin at inscoe {org}) # Searches the mail my $logs for a given address as a history of activity # Check arguments if ( $#ARGV == -1 ) { print "Usage: mlog user\@addy.com\n"; exit 1; } # Globals my $log1="/var/log/maillog"; my $log2="/var/log/maillog.0"; my $log3="/var/log/maillog.1"; my $log4="/var/log/maillog.2"; my $log5="/var/log/maillog.3"; my $log6="/var/log/maillog.4"; my $log7="/var/log/maillog.5"; my $log8="/var/log/maillog.6"; my $log9="/var/log/maillog.7"; my $search=$ARGV[0]; my @logrecs=(""); $sent=0; $ok=0; my $prev_msgid=""; # Find Message-ID's print "Collecting Message-ID's for address: $search...\n"; @logrecs=`grep $search $log1 $log2 $log3 $log4 $log5 $log6 $log7 $log8 $log9`; if (!@logrecs) { print "mlog: no records were found containing $search.\n"; exit 1; } # Process the log records my ($id, @msgids, $counta); foreach $rec (@logrecs) { my ($junk1, $junk2, $junk3, $junk4, $id, $junk5, $junk6, $junk7, $junk8, $junk9) = split (":", $rec); $id=~ s/\[.*\]//; $id=~ s/ *//g; push (@ids, $id); $counta++; } print "$counta records were found, "; # Now sort the msgids @tmp = sort (@ids); # Now remove dupes %seen = (); foreach $item (@tmp) { push(@msgids, $item) unless $seen{$item}++; } my $countb = scalar @msgids; print "of which $countb unique Message-ID's selected.\n"; if ( $#ARGV == 0 ) { print "MSGIDS: @msgids\n"; } # Now search the my $logs for each message id if ( $#ARGV == 0 ) { print "Processing Message-ID's...\n"; } foreach $msgid (@msgids) { if ( $#ARGV == 0 ) { print "\n*** Message-ID: $msgid...\n\n"; } @found=`grep $msgid $log1 $log2 $log3 $log4 $log5 $log6 $log7 $log8 $log9`; foreach $fnd (@found) { my ($logfile, $date_hour, $min, $sec_ip_srvr_sft, $id, $deliver, $junk10, $junk11, $junk12, $junk13_mlr_pri_relay_stat) = split (":", $fnd); if ( $#ARGV == 0 ) { print " $fnd\n"; } if ( $fnd =~ m/stat=/ ) { my ($j1, $j2, $j3, $j4, $j5, $j6, $j7, $j8, $stat) = split ("=", $fnd); # The $prev_msgid is a hack because we were double logging for a while if ( $stat =~ m/Sent/ ) { if ( $prev_msgid ne $msgid ) { $sent++; $prev_msgid = $msgid; if ( $stat =~ m/ok/ ) { $ok++; } if ( $stat =~ m/Ok/ ) { $ok++; } } } if ( $#ARGV == 0 ) { print " Status=$stat\n"; } } } } print "Summary for $search: $countb messages arrived at the relays, $sent were received at the remote end successfully.\n\n"; exit;