stevbutt has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, Wisdom is what I seek
I Have been trying to process several different log formats with some success but the mail ones have me a little stuck
Here is what my source data looks like
May 2 07:06:20 lon.mail.net exim[1234]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e <= it_ndt_bounces@new.itunes.com H=smtpmail.com [21.5.10.4] I +=[8.4.14.4]:25 P=esmtp S=1966 id=1603882764.112965659.1335927964793.M +ail.cboxp@ednabay.apple.com T="New on iTunes: One Thing And, Then Ano +ther, Cooking Apps,\n Great Deals on First Seasons, and M" May 2 07:06:20 lon.mail.net exim[1234]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e <= it_ndt_bounces@new.itunes.com H=smtpmail.com [21.5.10.4] I +=[8.4.14.4]:25 P=esmtp S=1966 id=1603882764.112965659.1335927964793.M +ail.cboxp@ednabay.apple.com T="New on iTunes: One Thing And, Then Ano +ther, Cooking Apps,\n Great Deals on First Seasons, and M" May 2 07:06:20 lon.mail.net exim[1235]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e => peterpiper <peterpiper@nosuchdomain.net> R=local_mail T=lo +cal_maildir_mail_drop
I have code now which processes basic syslog type entries into a number of fields
#!/usr/bin/perl use strict; use warnings; no warnings q{uninitialized}; while (my $line = <STDIN>) { chomp($line); my ( $mon, $day, $time, $loghost, $prog, $remainder ) = split m{:?\s+}, $line, 6; my %monthNos = do { my $no = 0; map { $_ => ++ $no } qw{ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec }; }; my ( $user ) = $remainder =~ m{user=([^,]+)}; my ( $rip ) = $remainder =~ m{rip=([^,]+)}; $remainder =~ tr/"/'/; my $yr = q{2012}; my $csv = sprintf q{%02d/%02d/%s %s,%s,%s,"%s",%s,%s}, $day, $monthNos{ $mon }, $yr, $time, $loghost, $prog, $remainder, $ +user, $rip; print "$csv\n"; }
My problem now is that it looks like in exim various fields mean different things depending on whether the string contains <=, =>, == or even **
Because my files contain potentially millions of lines I am looking for an efficient way of effectively saying
if contains <= then ...... else if contains => then ..... else if contains == then .... else if contains ** then .... else somethingelse etc
Plus any tips if the way I am doing this now could be made faster
Many Thanks IA
Steve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Process mail logs
by GrandFather (Saint) on Aug 12, 2012 at 23:35 UTC | |
by stevbutt (Novice) on Aug 13, 2012 at 14:53 UTC | |
by GrandFather (Saint) on Aug 13, 2012 at 22:59 UTC | |
by stevbutt (Novice) on Aug 13, 2012 at 23:56 UTC | |
|
Re: Process mail logs
by GrandFather (Saint) on Aug 12, 2012 at 23:24 UTC | |
by stevbutt (Novice) on Aug 13, 2012 at 11:18 UTC | |
|
Re: Process mail logs
by Kenosis (Priest) on Aug 12, 2012 at 23:17 UTC | |
by influx (Beadle) on Aug 13, 2012 at 07:45 UTC | |
by Kenosis (Priest) on Aug 13, 2012 at 20:19 UTC | |
by stevbutt (Novice) on Aug 13, 2012 at 10:41 UTC | |
by aaron_baugher (Curate) on Aug 13, 2012 at 12:19 UTC |