in reply to Script Help
If the text within your OP represents a single line from a closed log file, i.e., if you are not trying to tail a constantly growing log file, the following might represent a possible approach to a solution (untested):
use warnings; use strict; my $log_file = 'file.log'; my $uid = 'xy1234'; my $threshold = 20; my @occurrences; open my $fh_log, '<', $log_file or die "opening $log_file: $!"; LINE: while (defined(my $line = <$fh_log>)) { next LINE unless $line =~ m{ uid=$uid }xms; push @occurrences, $line; } close $fh_log or die "closing $log_file: $!"; if (@occurrences > $threshold) { print "occurrences for $uid above $threshold \n"; print @occurrences; }
Of course, the print statements at the very end will have to be replaced with code to compose and send an appropriate e-mail message, etc., but I assume you know how to do that. (In any event, I'm not the best one to ask about that.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Script Help
by Anonymous Monk on Jan 22, 2010 at 04:11 UTC | |
by AnomalousMonk (Archbishop) on Jan 22, 2010 at 04:50 UTC |