----- Original Message -----
From: Nick Chettle <[EMAIL PROTECTED]>
Date: Wednesday, March 16, 2005 7:02 am
Subject: Perl Analyzing Maillog
> Hi All,
Hello,
>
> I am trying to write a simple script that will analyze a Postfix
> maillog. The basic idea is that you give it an e-mail address and
> it
> will print all the relevant lines. In order to achieve this, you
> first
> need a message ID, you can then search for the id and bring all
> the
> relevant information.
>
> This is what I have so far:
>
> #!/usr/bin/perl
>
> print "Please enter an e-mail address: ";
> chomp($email = <STDIN>);
>
> open MAILLOG, "/var/log/maillog";
>
> while (<MAILLOG>) {
> if (/$email/) {
> if (/[A-Z1-9]{8}/) {
> $msgids[$_] = $&;
> }
> }
> }
>
> This works fine and it builds an array of all the message id's. I
> now
> need an efficient way of searching through the log again and
> pulling out
> all lines that contain a message id.
You are already doing it, why not keep the results first time around ?? One
was it to create a Ref to Hash Ref of Array's [ I prefer this, others may
simply do a HoA ]
while (<MAILLOG>) {
if (/$email/) {
if (/[A-Z1-9]{8}/) {
push @{ $msgids->{$1} }, $_;
}
}
}
>
> I can do this with:
>
> for (@msgids) {
> system "cat /var/log/maillog | grep $_";
> }
>
> But it's certainly not a very Perl way of doing it and it's less
> than
> efficient as I have to cat the entire maillog for each message id.
>
> I've been trying to open the filehandle again and then somehow get
> foreach to go through it but haven't had much sucess. Can anyone
> advise
> if I'm looking along the right lines or if there is a better way
> of
> doing it?
>
> Thanks, Nick
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>