Link to home
Start Free TrialLog in
Avatar of Daniele Brunengo
Daniele BrunengoFlag for Italy

asked on

Grep and email results, if any

Hello, I am trying to have a script on my Centos 6.5 server send me an email if grep finds particular content inside, for instance, the maillogs.

So I wrote this and put it in the cron.daily directory:

#!/bin/sh

grep -H "spamhaus" /var/log/maillog* | mail -s "Blacklist Alert!" mail@mymail.it

Open in new window


It works, but my problem is I'll get an email even when nothing is found and the body is empty.

So, is there a way to have mail not send anything if the body is empty? I know other mail software can do this with a -E option, but it doesn't seem to work with mail.

Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniele Brunengo

ASKER

Love the shortest version! I'm a linux beginner, couldn't have done it without your help. Thanks!