How can I only receive emails from cron if there are errors?
You could wrap your cron invocations with cronic, a shell script which eats cron output unless the return code of the invoked process is non-zero or there is non-trace error output.
To use cronic, download the script to a suitable location, such as
/usr/local/bin. Your crontab entries must be prefixed with the path to the script (e.g.
/usr/local/bin/cronic), or simply
cronic, provided your
PATH is set properly.
Do note that "errors" is an ill-defined term in your question and requires careful definition. For cronic to be useful, you must ensure the jobs you wrap with cronic report errors in one of the ways it defines an error condition. Implicit methods of reporting, such as writing text strings to
STDOUT, will require further thought to make this compatible with cronic or another cron reporting mechanism.
Other wrappers are available, as linked from the cronic site: