Daniele Brunengo
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:
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.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER