Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: best way to....

by dbs (Sexton)
on Aug 31, 2011 at 20:03 UTC ( #923495=note: print w/replies, xml ) Need Help??


in reply to Re: best way to....
in thread best way to....

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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://923495]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2021-04-23 17:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?