0

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.

João Paulo
  • 127
  • 7
  • 1
    Does this answer your question? [How to make crontab email me with output?](https://askubuntu.com/questions/536766/how-to-make-crontab-email-me-with-output) – user68186 Jun 20 '21 at 00:15
  • Are you asking why your `MAILTO` environment variable needs to be set explicitly in the crontab, rather than being inherited from somewhere? – steeldriver Jun 20 '21 at 01:30
  • My understanding is that crontab by default will automatically email me when there's an error with the script it runs. When I have "asdfadsf" in my script, that throws an error. However, crontab is not emailing me that this script threw an error. – lightstream Jun 20 '21 at 02:02
  • 1
    Without a `MAILTO` variable, 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 as `ssmtp` or the like). – steeldriver Jun 20 '21 at 10:39
  • Thank you @steeldriver – lightstream Jun 21 '21 at 12:40

0 Answers0