output=$(grep line /var/log/file); [[ -n "$output" ]] && mail -s Log firstname.lastname@example.org
Or you can make this into a cron job and then if it produces any output it will email the users. You can edit the /etc/aliases file (and then run newaliases command) to send mail to address not on the box.
Ex of cron entry (You won't be able to set the subject line thogh
1 0 * * * grep line /var/log/file
Or you can get the ifne utility - This is probably what you want
grep line /var/log/file | ifne mail -s Log email@example.com
The ifne command it availabe from the epel repo for centos and RHEL. I can't find a link to the man page online but there it is
ifne - Run command if the standard input is not empty
ifne [-n] command
ifne runs the following command if and only if the standard input is
-n Reverse operation. Run the command if the standard input is emp-
Note that if the standard input is not empty, it is passed
through ifne in this case.
find . -name core | ifne mail -s "Core files found" root
Copyright 2008 by Javier Merino
Licensed under the GNU GPL