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="[email protected]"
* * * * * /home/user/cron-test.sh
How do I receive an email when an error occurs.
MAILTOenvironment variable needs to be set explicitly in the crontab, rather than being inherited from somewhere? – steeldriver Jun 20 '21 at 01:30MAILTOvariable, AFAIK it will attempt to mail to the crontab's owner locally, using something equivalent to[email protected]. 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 asssmtpor the like). – steeldriver Jun 20 '21 at 10:39