Many thanks for all your wonderful solutions. Although a db solution sounds great but I'm trying to do this solo interacting with our log files. Another thing I may not have mentioned is newer entries of ppl making cert changes would be possible. *** So ultimate outcome would be if someone makes a cert change during the current hr, It will look for a match and if found send out email alert. If nobody makes and cert changes during that hour then all is well. But what happens if another change is made by someone during the hour, I'm trying to avoid the previous match and only print out and alert the newest match. Updated code is below

#!/usr/bin/perl -w use strict; my $flag = 0; my $few = shift || 1; my $id; my $newline; my $partyId; my $userid; my $tid; my $infile; my @Takeraccounts = ('SCN','CX'); my $mail_dest = 'xxxxx@cx.com'; my %TIME; ( $TIME{SEC}, $TIME{MIN}, $TIME{HOUR}, $TIME{MDAY}, $TIME{MON}, $TIME{YEAR}, $TIME{WDAY}, $TIME{YDAY}, $TIME{ISDST} ) = localtime(time); my $OLD_MIN=$TIME{MIN}; my $OLD_HOUR=$TIME{HOUR}; my $cmd = "cat /raid/logs/`date +%H`"; my $out_file = "/home/resource/certchange.txt"; open FF, "$cmd |"; open (OUT, ">> $out_file") || die "Cannot open $out_file"; # temp file + to which to write the formated output while (<FF>) { my $line = $_; #chomp ($now_time); $line =~ s/\n/ /; if ( /Updating cert/ .. /,permissions/ ) { $newline = "$line"; if ( $line =~ /Updating cert.*updated by (\w+)/ ) { $id = $1; } if ( $newline =~ /UPDATE_STATE.*id:(\w+).*partyId:(\w+),permis +sions:/ ) { $userid = $1 ; $partyId = $2; foreach (@Takeraccounts) { if ($partyId =~ /$_/) { print OUT "Certificate cert Updated by $id for userid $userid +, PartyID $partyId\n"; open ML, "| mutt -e\"set realname='Support'; set use_from=yes; + set from='support\@cx.com'; set envelope_from=yes\" -s ' Alert! cert + CHANGED' -i $out_file -- $mail_dest"; close ML; } } } } } close FF; close (OUT); unlink $out_file;

In reply to Re^2: How can one open a filehandle in realtime or current log by new2perl2016
in thread How can one open a filehandle in realtime or current log by new2perl2016

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.