Score:0

Crontab is not emailing me errors

cn flag

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

Can anyone help me with this? I Would like to get an email when an error happens.

Thanks.

ar flag
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)
hr flag
Are you asking why your `MAILTO` environment variable needs to be set explicitly in the crontab, rather than being inherited from somewhere?
lightstream avatar
cn flag
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.
hr flag
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).
lightstream avatar
cn flag
Thank you @steeldriver
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.