I have a bash script (daily.sh) that runs daily as a cron job for user pi. Recently, I received an email notification on my RPi that an error had occurred in daily.sh. It turned out that this email notification was very useful, but I don't understand how this was "triggered" - i.e. what caused it to be sent??

Some background may be useful or relevant:
I've learned today that the exim4 MTA on my RPi was installed months ago as a Suggested Dependency when the at utility was installed. exim4 is not a "default" install - not part of the RPi OS Lite distro I use.

The text of the emailed error message:

Date: Thu, 07 Jan 2021 06:00:32 -0600
From: Cron Daemon root@raspberrypi4b.local
To: pi@raspberrypi4b.local Subject: Cron pi@raspberrypi4b /home/pi/daily.sh 2 >> /home/pi/cron_error.log

/home/pi/daily.sh: line 27: [: !=: unary operator expected

I don't think this is relevant to my question, but I'll mention it "just in case":
As it turns out, this error was not redirected to the cron_error.log because I mistakenly said, 2 >> instead of 2>> in my crontab.

I know that it's possible to declare the MAILTO variable in a crontab (i.e. MAILTO=pi), but there is no such declaration in the crontab for user pi (or any other user for that matter). AFAICT there is no default "global" declaration for cron either. Yet, somehow, cron knew to send this error message to the inbox for pi. How did that happen?

  • Cron runs stuff with /bin/sh (dash). That's the not same as /bin/bash and the syntax for unary operators is different. – Dougie Jan 16 at 13:08

If a process started by crontab writes to stdout or stderr crontab sends an e-mail with that text to the local users (process owner) mail address provided that an MTA is installed and configured for local delivery.

If you had correctly redirected stderr to a file or /dev/null it should not send a mail, as it gets no output on the output channels.

You can also suppress emails with the


entry in the crontab file. But simply not using MAILTO="..." does not switch off mails.

I've searched the internet for a explanation from a more experienced (than me) english writer ;-).: here's one

  • Very good! I had missed the bit about the MAILTO variable being the default. It was in man 5 crontab, but TLDR :) Adding to the confusion, the exim4 MTA was broken sometime after I installed it with a faulty configuration setting for IPv6. – Seamus Jan 16 at 9:14

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.