I have a script called cron-test.sh
with a line of code to trigger an error:
#!/bin/bash
echo "Cron Tab is Running"
asdfadsf
My crontab -e
has this:
* * * * * /home/user/cron-test.sh
I can't seem to get any emails of the error in my script, I know email configuration is set up properly because I tested the following in crontab -e
and I get emails every minute telling me "Cron Tab is Running".
MAILTO="me@email.com"
* * * * * /home/user/cron-test.sh
How do I receive an email when an error occurs.
MAILTO
environment variable needs to be set explicitly in the crontab, rather than being inherited from somewhere? – steeldriver Jun 20 '21 at 01:30MAILTO
variable, AFAIK it will attempt to mail to the crontab's owner locally, using something equivalent touser@localhost.localdomain
. The mail should end up in/var/mail/user
(although for that to work, you need a full mail server running on the localhost I think - rather than a mail forwarder such asssmtp
or the like). – steeldriver Jun 20 '21 at 10:39