I did not quite follow your suggestions...sorry, but here is the code.
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;
my ($percnt,$threshhold @p,$cntr, $flag, $CF, $alertaddr, $Esubject,);
my $log = qq(/var/adm/USE_monitor.csv);
my $cntrF = qq(/var/adm/USE_monitor.cntr);
open LOG, "+<", $log or die "'$log' did not open $!\n";
... {snip} ...
if ( $percnt >= $threshhold ) {
write (LOG);
push @p, $percnt;
}
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";
print $cntr;
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;
}