Is there a cheap way to monitor a log file like tail -f log.txt
, then if something like [error]
appears, execute a command?
Thank you.
Is there a cheap way to monitor a log file like tail -f log.txt
, then if something like [error]
appears, execute a command?
Thank you.
I also found that you can use awk to monitor for pattern and perform some action when pattern is found:
This will execute command when pattern is found in the log. Command can be any unix command including shell scripts or anything else.
Batter and simple:
Simple Automated Solution that covers a lot of scenarios:
USAGE:
EXAMPLE:
With this tool, you can monitor specific patterns in a log file and then trigger a command or script when the patterns are found...or NOT Found!
The scripts or commands can be set to run based on thresholds and exit codes.
Tool can be downloaded directly here.
An even more robust approach is monit. This tool can monitor very many things, but one of them is that it will easily tail one or more logs, match against regex and then trigger a script. This is particularly useful if you have a collection of log files to watch or more than one event to trigger.