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 [email protected]
To: [email protected] 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?