in reply to Re: Buffered read and matching
in thread Buffered read and matching
Right, I wanted to suggest some state machine along this too:
However, all solutions I have seen so far trigger evaluation with the next timestamp only. When using tail -f, the error will be processed only when the next log-line with a time-stamp is encountered - which might happen some hours or days later. IF seeing an error ASAP is important to the OP, the evaluation should be triggered additionally by matching for }; or by some timeout-mechanism, e.g. using alarm().#!/usr/bin/perl use strict; my @lines; sub flush { return unless grep(/'Errors'/, @_); print "Got:\n\t", join ("\t", @_), "\n"; } while (<>) { # trigger on last line of an error message flush(@lines,$_),@lines=(),next if m{^\s*\};\s*$}; # triggger on next timestamp flush(@lines), @lines=() if m{^\s*\[\d\d\d\d\/}; push(@lines, $_); } flush(@lines);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Buffered read and matching
by jethro (Monsignor) on Oct 15, 2008 at 13:41 UTC |