Bowie Bailey wrote:

Jason Gerfen wrote:
Bowie Bailey wrote:
Jason Gerfen wrote:
I am looking to do something which I am not sure perl can do.  I
would like to be able to issue a system command ex. tail -f /file
and loop over that command while sorting the output.  Is this
possible? And if so could I see an example?
  open(LOG, "tail -f /var/log/messages |");
  while (<LOG>) {
      if (/something important/) {
          print "Found something...\n";
      }
  }
  close LOG; # Never get here, but for completeness...

I'm not sure what you mean by sorting the output.  Since there is
continuous input, there will be continuous output.  You could sort
and display aggregated output at intervals rather than having a
real-time output stream.
Really?  So constantly piping the results of a log file through a
function to sort the data is not the best method of giving real time
data based on the piped output of a log file?

Sure, it just depends on exactly what you mean by "Sort the data".  What
kind of output are you looking for?

I have a few programs that do this exact thing.  They tail the log file
and page or email me when they find something.  The only problem I have
had is that it seems like the pipe will eventually break if you leave it
running for long enough.

Well I am 'attempting' to write a simple perl daemon that will listen or 'tail -f /var/log/messages' for any iptables log which matches a 'DROP'ed packet. Upon seeing a matching condition it will fork a new process and then begin sorting the data and send me alerts etc. Does that help explain it a bit more? I can include code if needed.

--
Jason Gerfen

"When asked what love is:
Love is the Jager talking."
~Craig Baldo

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to