I'm trying to grab each line from sendmail syslog file and combine the different lines where the message id's are the same and combine them to show source and destination.
p3D8Bj1f007915 user1@domain.com p3D8EF8n007918 user2@domain.com p3D8Bj1f007915 server101@domain.com p3D8EF8n007918 server111@domain.com
My goal is the have one hash with output like:
p3D8Bj1f007915 user1@domain.com sent message from server101@domain.com p3D8EF8n007918 user2@domain.com sent message from server111@domain.com
So far, the code below only produces two simple hashes that are only uniq by msgid:
#!/bin/perl open (FH, "/var/log/syslog") ; foreach $lin (<FH>) { 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 fr +om= 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"; }
Thanks for looking!

In reply to sendmail logging combine two hashes by chanslor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.