Sending mail from command line if body not empty

Posted by cdecker on Server Fault See other posts from Server Fault or by cdecker
Published on 2012-01-15T00:39:59Z Indexed on 2012/07/11 9:17 UTC
Read the original article Hit count: 200

Filed under:
|
|
|

I'd like to write a simple script that alerts me if a log changes. For this I'm using grep to find the lines I'm interested in. Right now it works like this:

grep line /var/log/file | mail -s Log [email protected]

Problem is that this sends a mail even if no matching lines are found. The mail utility from mailutils seems to have no switch telling it to drop mails that have an empty body.

Is there a quick and easy way to do so?

© Server Fault or respective owner

Related posts about email

Related posts about bash