Skip to content

Instantly share code, notes, and snippets.

@dkubb
Created November 19, 2010 15:55
Show Gist options
  • Save dkubb/706679 to your computer and use it in GitHub Desktop.
Save dkubb/706679 to your computer and use it in GitHub Desktop.
Sends an email to an address when a log is written to
tail -0f test.log | ruby -ne 'open("|mailx -s Log dan.kubb@gmail.com", "w", &:print)'
@dkubb
Copy link
Author

dkubb commented Nov 19, 2010

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 :)

@dkubb
Copy link
Author

dkubb commented Nov 19, 2010

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