1) How often does this script run?
2) How do you prevent bombarding the email address with many emails related to the same error?

Perl has a very good way of "grepping". Use the Perl way instead of calling external GREP. This will be much faster.

Handling (2) requires knowledge of your log file which your post doesn't have.

Update:
This is not so good: if (-e $logFile) {}
The log file could perhaps "go away" for a brief time during some pruning or archiving process.
The next steps in your code are not guaranteed to work.

Use open() to get a file handle. Process the results of that file handle. Once you have a valid file handle, what happens in the directory (like rename or even delete) doesn't matter.

I am assuming that your process runs "in the background", a Windows Service or Unix Daemon.
Think about what happens if you monitoring program fails or fails to start? There are a lot of issues.

Update:

So some code (untested) could look like this:

my $logFile = "/icd/rc/genus22/logs/genus_221/v22.10-d037/lnx86_64_opt +/1/tamper.log"; open (my $fh, '<', $logFile) or reportErr($!); if ( grep{": FAIL"}<$fh>) #FAIL found anywhere in file! { do something... exit or return... } # text "Fail" not found if here do whatever... sub reportErr { my $error_text = shift; do something... }
However, the problems I mentioned above still exist. If FAIL appears anywhere in the log file, this will send an email every time that this script runs! If somehow the logfile cannot be opened, same problem, this will send an email every time that this script runs!

A working script needs to address both of these issues. I'd need to know more about your application to find the "best" answer. Basically you need some kind of a persistent flag that has the effect of "throttling down" the error emails. If your script is running continuously, you could keep this as a global variable. Another technique could be to use the file system. When sending an email create a file "last_email_sent", you could check the file modification date of that file and don't send another email unless its been say at least one hour? You don't have to put any data in the flag file itself. Its perfectly legal to have a file with 0 bytes in it. However, perhaps you could put something in this file that perhaps references a line number in the log file or perhaps a date/time value associated with the error. Maybe you don't want to keep reporting the same error over and over again? Maybe after handing an error, you just leave the log file alone, remembering that you've already reported the last error and don't report again unless a new error shows up? Anyway what you want to prevent is flooding the Error_email_box with messages.


In reply to Re: how to grep from a log file by Marshall
in thread how to grep from a log file by noviceuser

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.