Debian – Crontab job not emailing on failure

croncurldebianemailerror handling

I have a cron job on Debian:

1 * * * * /home/paradroid/bin/myscript.sh >/dev/null

There is an installed and configured MTA, and I have received emails when the script has a syntax error, so I have always thought that I would be informed when anything goes wrong.

The script downloads a file using curl through a proxy. Recently the proxy has failed so curl could not download. It is the last command in the script, which has been exiting with the error code 7.

I thought I would be getting emails when this happens, but I have not.

How come I get email alerts from something like syntax errors in the script, but I have not been getting them when the script fails to do its job and exits with an error code?

Is something wrong, or do I have to get the script to email me directly when there has been an error with curl?

Best Answer

I'm assuming your cron email settings are all correct, and you otherwise get emails.

Your sending all stdout to /dev/null, so anything that prints error messages must output them to stderr. You might want to make sure everything in the script is outputting correctly.

At times I have had to work with third party code, which was sending everything to stdout. In those cases, I usually hack up an error check. It's not pretty, but neither are most shell scripts.

Related Question