p3D8Bj1f007915 user1@domain.com
p3D8EF8n007918 user2@domain.com
p3D8Bj1f007915 server101@domain.com
p3D8EF8n007918 server111@domain.com
####
p3D8Bj1f007915 user1@domain.com sent message from server101@domain.com
p3D8EF8n007918 user2@domain.com sent message from server111@domain.com
####
#!/bin/perl
open (FH, "/var/log/syslog") ;
foreach $lin () {
chomp($lin) ;
next unless $lin !~ /^\s*$/ ; # Gets rid of blank lines
if ($lin =~ /sendmail-listen/){
$lin =~ s// ; #removes < from the line
$lin =~ s/>,// ; #removes > from the line
($a,$b,$c,$d,$e,$msgid,$g)=split(' ',$lin) ;
$msgid =~ s/:// ;
#print $g,"\n"; #make sure i'm grabbing the to= and the from= for the follow $destname
#TO
if ($g =~ /^to/){
($to,$destname)=split('=',$g) ;
$destname =~ s/,// ;
chomp($destname) ;
$to{$msgid} = $destname ; #Two scalar values going into a hash called $to.
}
#FROM
if ($g =~ /^from/){
($fr,$fromname)=split('=',$g) ;
$fromname =~ s/,// ;
chomp($fromname) ;
$from{$msgid} = $fromname ; #Two scalar values going into a hash called $from.
}
} #ENDS sendmail-listen
}
close ( FH ) ;
#print the $to hash
foreach $too (sort keys %to) {
print "$too $to{$too}\n";
}
#print the $from hash
foreach $fromm (sort keys %from) {
print "$fromm $from{$fromm}\n";
}