Under Linux, what's a simple way to automatically watch a logfile, and email me if a certain string appears? I have an application that will log certain failures to a logfile, but has no built-in way of sending alerts or executing scripts on failure. I suppose I could rig something up with tail -f and some shell scripts, but I'd rather use an existing maintained tool if it exists.
Linux – How to Send Email Alert on Log File Entry
alertsemaillinuxlog-files
Best Answer
I checked out several of the options mentioned on this page, and ended up using something far simpler: swatch.
Those other systems are great for dealing with existing system logs, or with software where you don't have control over the output. I just didn't want to write a bunch of code to do email notifications just yet. So I just created a swatch file like this:
And then started it up with
It's crude, but since I control the logfile output, I don't need anything more complicated yet.