you can pipe the output of a crontab cron to the mail command to get its output, for example:
0 6 * * * /usr/bin/php script.php | /bin/mail -s `daily_order_validation` spencer@example.com
Sends an email to spencer every day.
But what if you only want NONBLANK emails? You could do something like:
data=$(/usr/bin/php script.php); [[ -n "$data" ]] && mail -s 'only non blank email' spencer@example.com<<< "$data"
what if you only want an email if the script output has the word ERROR in it?
data=$(/usr/bin/php script.php); [[ $data == *ERROR* ]] && mail -s 'only non ERROR email' spencer@example.com<<< "$data"
src: http://unix.stackexchange.com/questions/13326/how-to-pipe-output-from-one-process-to-another-but-only-execute-if-the-first-has/13337#13337
and http://unix.stackexchange.com/questions/13326/how-to-pipe-output-from-one-process-to-another-but-only-execute-if-the-first-has