Created
November 19, 2010 15:55
-
-
Save dkubb/706679 to your computer and use it in GitHub Desktop.
Sends an email to an address when a log is written to
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tail -0f test.log | ruby -ne 'open("|mailx -s Log [email protected]", "w", &:print)' |
I'll post an explanation of what this is doing shortly. It may look simple, but there are actually a few subtle things going on here that are not immediately clear.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I plan to use this for monitoring a few critical error logs where a write to it needs to be investigated. This also works nicely if you're monitoring a (mysql) slow query log. Previously I'd used a much larger perl script but I decided to see if I could do it in a bash one-liner.
In my experience, this forces me to deal with noisy error logs quickly, so that the only thing being written to the logs are real actual errors that need human intervention. Sure, in the beginning I tend to get spammed, but forcing myself to deal with the pain rather than ignore it (which is all too easy with logs) ensures that the problems actually get dealt with.
Plus if there are cases where I absolutely can't figure out the cause of a problem, that's what grep -v is for :)