I trying to write code that checks for values greater than 90, write to a log, if -s log alert via email. Then, because of the -s test print a "$flag\n" to a local file as a way to keep track of emails sent for the next run 30 minutes later or 28 hours later. So like the code below, my problem is the flag in the file never gets cleared for the next run, so the logic
elsif ( $cntr > 2 ) { for (@p) { ....
will never be executed and if I truncate the $cntrF file the flag will always remain at 1 and thus $cntr will too. So I need a simple way to keep track of how many times -s succeeds (aka an email is sent) for every run of this job over 4 or 5 days which then the flag counter can be set to zero.
use strict; use warnings; if ( -s $log ) { $cntr = 0; $flag = 1; open $CF, ">>", $cntrF or die "'$cntrF' did not open $!\n"; print $CF "$flag\n"; sleep 1; close $CF; sleep 1; open $CF, "+<", $cntrF or die "'$cntrF' did not open $!\n"; while (<$CF>) { while (m/\b$flag\b/g) { $cntr++; } } print $cntr; if ( $cntr <= 2 ) { _mailme($alertaddr, $Esubject, $log); $CF->close; } elsif ( $cntr > 2 ) { for (@p) { if ( $_ >= 99 ) { _mailme($alertaddr, $Esubject, $log); last; } } $CF->close; } else { $CF->close; } }
thnkU!

In reply to best way to.... by dbs

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.