Link to home
Start Free TrialLog in
Avatar of sparkie_77
sparkie_77

asked on

Parse postfix mail logs for addresses then compare them to a addresses :qdatabase

Hi Guys,
I am trying to parse a postfix log file for from addresses then compare them to a database.
SO I need to extract the email from: postfix/qmgr[24973]: 199D81C28579: from=<blah@blah.com>, size=6928, nrcpt=1 (queue active) then run a query to find it in a database. Need this quick!

 Tried using Email::Find and it wouldn't work.
#!/usr/bin/perl -w
use strict;
use Email::Find;

open (SRC, "/var/log/maillog") || die "can't open source file $!";
open (DEST, ">desination.txt") || die "can't open destination file $!";

my $finder = Email::Find->new(sub { my($email, $orig_email) = @_;
print DEST $email->format,$/;
return $orig_email;
});

while(my $text = <SRC>) { $finder->find(\$text); }

close SRC;
close DEST;
ASKER CERTIFIED SOLUTION
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Perl_Diver
Perl_Diver

if there are spaces before or after the = sign you may have to alter the regexp above

  /from\s*=\s*<([^>]+)>/i and print DEST "$1$/"