LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   A live log monitor script ? (https://www.linuxquestions.org/questions/linux-software-2/a-live-log-monitor-script-26000/)

ifm 07-17-2002 03:15 PM

A live log monitor script ?
 
Got a question/request.

I want to make a simple script that watches a log "in real time" and then does something when something is seen happen in a log file.

I am capable of doing all the glory of the action, however I cannot find a good way (any way actually) to make a script run and monitor a log file in real time while the file is being written too by another program. OR make the script watch to see if the log file is written too, then reads the end of the log and sees if something happened that it should do something with.

Any ideas? Am I dreaming in thinking this can happen?

Any pointers to an example script, code snip, or idea... let me know!
Thanks.

Mik 07-19-2002 02:54 AM

There might be more elegant ways but maybe something like this could be an idea.

First run something like 'tail -f logfile >> tempoutput&'
That will append anything that gets added to the logfile to a tempfile. All you have to do in your script is a loop which periodically checks the tempfile and then clears the contents.

Code:

#!/bin/bash
tail -f logfile >> tempoutput&

while [ 1 ]
do
  grep ERROR tempoutput

  cat /dev/null > tempoutput
  sleep 1
done



All times are GMT -5. The time now is 07:08 PM.