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?


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.

| improve this answer | |
  • It looks like curl's error message come out through stderr, as nothing is shown with the -Ss switch. Isn't that odd? I guess the only way around it would be to get the script to check for an error code and email me directly if there was? – paradroid Jan 1 '12 at 21:54
  • 1
    Yup I just tried messing with curl, and seeing what still shows when > /dev/null. It seems like only in syntax related errors, print gets correctly output to stderr. For example if I download a bogus file, all output goes to stdout, therefor I wouldn't know the wiser. – J. M. Becker Jan 1 '12 at 22:07
  • This is one of those times, as a SysAdmin, I had to just "make due". Its not pretty, but a manual error check gets the job done. – J. M. Becker Jan 1 '12 at 22:08
  • It was a bug! See my answer. Thanks for your help. – paradroid Jan 3 '12 at 4:09

After talking to some people on #curl on Freenode, a dev mentioned that there has been a bug in curl for around a decade (before 7.23.0) where an option parsing error treated -Ss (--show-silent --show-error) as -s (--silent), so all output is suppressed, including stdout.

The solution (before 7.23.0) is to use -sS instead, or long options.

That nasty bug caused me a lot of confusion and let a rather important cron job fail without me knowing about it for several days!

| improve this answer | |

Cron only emails you the output streams stdout and stderr if the contain output.

You could trigger cron to notify you by doing an echo conditional on the return code of program. This does assume the program sets a failure status appropriately. This can be done by tacking || echo Failure status $? to the end of the command line. Tune the message to your liking. The long forms are to wrap the command with an if then fi construct or test the return code after the command is run.

| improve this answer | |
  • It turned out to be a bug, which I have detailed in my answer. Thanks. – paradroid Jan 3 '12 at 4:10

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.