1

I have an Ubuntu 14.04 virtual private server.

There are a few cronjobs defined:

00 03 * * * cd /root && ./backupJob.sh
00 04 * * * sudo -u www-data php /var/www/dir/htdocs/bin/indexer.php
00 05 * * * cd /root && ./cleanUpUploadedFilesJob.sh

Now the sysadmin receives an email for every cronjob that's executed, even on success. Note that I have a postfix running on the same machine and there is no MAILTO="" in the crontab.

The goal is to only receive an email when the script has an exit value other than 0.

If I add 1>/dev/null to every line, will my standard out be redirected? Will the behavior for standard error stay the same otherwise?

1
  • Why don't you just change them to command || emailAdmin.sh where emailAdmin.sh is a script that send the email? That way, it will only be sent on failure. – terdon Jan 16 '17 at 13:16
1

If i add 1>/dev/null to every line, will my standard out be redirected?

Yes, to /dev/null. In effect, the STDOUT will be discarded and hence no mail will be sent for STDOUT.

Will the behavior for standard error stay the same otherwise?

Yes; just to note, if you need to redirect STDERR, you need to use file descriptor 2, for example, redirecting to /dev/null (i.e. discarding the STDERR): ... 2>/dev/null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.