OK, this is what I have for the perl script so far. I got into trouble towards the end, and it doesn't like what i'm trying to do with the variable.
#!/usr/local/bin/perl
#use strict;
use locale;
use DBI;
use Cwd ;
my %sender_emails = () ;
my %recipient_emails = () ;
my %recipient_count = () ;
$logfile = '/data/log/maillog';
open(LOG, $logfile);
while (<LOG>)
{
($msgMon, $msgDay, $msgTime, $msgHost, $msgCmd, $QID, $from_to) = split(/\s+/, $_) ;
next if \(/from=<>/\) ;
next if \(/from=<root>/\) ;
if \(\($_ =~ /from=</\) && \($_ =~ /qmgr/\)\)
\{
\($tmpString, $from\) = split\("from=<", $_\);
\($from,$tmpString\) = split\(">", $from\);
$sender_emails \{$QID\} = $from;
\}
elsif \(\($_ =~ /to=</\) && \($_ =~ /smtp/\)\)
\{
\($tmpString, $to\) = split\("to=<", $_\);
\($to,$tmpString\) = split\(">", $to\);
$recipient_emails \{$QID\} = $recipient_emails \{$QID\} . "$to " ;
$recipient_count \{$QID\}\+\+ ;
\}
}
close(LOG);
foreach $myQID (keys %sender_emails)
{
$myto = $recipient_emails{$myQID} ;
$myfrom = $sender_emails{$myQID} ;
$tocount = $recipient_count{$myQID} ;
next if $tocount >= 6;
foreach $rcpt_group (values %sender_emails)
{
($1, $2, $3, $4, $5) = split(/\s+/, $_);
@rcpt = ("$1", "$2", "$3", "$4", "$5");
{
foreach $rcpt (@rcpt)
{
print $myfrom . "," . $rcpt . \n;
}
}
}
}
This is a working version of the last portion of the script.
foreach $myQID (keys %sender_emails)
{
$myto = $recipient_emails{$myQID} ;
$myfrom = $sender_emails{$myQID} ;
$tocount = $recipient_count{$myQID} ;
next if $tocount >= 6;
{
print $myfrom . "," . $myto . \n;
}
}
the only problem is that it prints out lines with message recipients greater than one in the following fashion.
sender@domain,recipient1@domain recipient2@domain etc.
when I ultimately need:
sender@domain,recipient1@domain
sender@domain,recipient2@domain
sender@domain,recipient3@domain
and so on...
this is what the log entries actually look like.
May 14 01:08:38 mail11 postfix/smtpd[86997]: 21F9C17ADDEB: client=domain.com[127.0.0.1]
May 14 01:08:38 mail11 postfix/cleanup[87530]: 21F9C17ADDEB: message-id=<00ec01c8b580$73d85d60$da0ba8c0@domain>
May 14 01:08:38 mail11 postfix/qmgr[9455]: 21F9C17ADDEB: from=<user@domain>, size=18310, nrcpt=3 (queue active)
May 14 01:08:39 mail11 postfix/smtp[86884]: 21F9C17ADDEB: to=<user@domain>, relay=domain [127.0.0.1]:25, delay=1, delays=0.21/0/0.45/0.39, dsn=2.0.0, status=sent (250 ok: Message 149052398 accepted)
May 14 01:08:39 mail11 postfix/smtp[87444]: 21F9C17ADDEB: to=<user@domain>, relay=domain.com[127.0.0.1]:25, delay=1.8, delays=0.21/0/1.1/0.51, dsn=2.0.0, status=sent (250 Ok: queued as E572B24807B)
May 14 01:08:39 mail11 postfix/smtp[87444]: 21F9C17ADDEB: to=<user@domain>, relay=mail.domain.com[127.0.0.1]:25, delay=1.8, delays=0.21/0/1.1/0.51, dsn=2.0.0, status=sent (250 Ok: queued as E572B24807B)
May 14 01:08:39 mail11 postfix/qmgr[9455]: 21F9C17ADDEB: removed
As always any comments, criticisms, and questions are welcome and appreciated.
-JJ