0

As we know that MAILTO is used for receiving any mail related to the Cron job. In my case I have three commands to execute, do I need to add MAILTO three times even if the receiver mail id is the same for each of the three commands? My jobs are running on a CentOS machine.

MAILTO=x@y.com
./first-Command

MAILTO=x@y.com
./second-Command

MAILTO=x@y.com
./third-Command

Or mentioning the mail id only once will work in my situation? like this:

MAILTO=x@y.com
./first-Command

./second-Command

./third-Command

I'm new to the Cron tool. Any idea/hint in the right direction will do!

2

The MAILTO variable, if set, is retrieved from the crontab file, so if it exist and is not "" then it will be used for all subsequent jobs in that file, just like if you had created a shell script like your second example. Therefor, setting it at the top of the crontab file is enough, just like you could change the crontab shell from sh to bash with SHELL=/bin/bash in the beginning of the file per the man file

1

One MAILTO per crontab file

man cron:

When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists).

1
  • 1
    That quote doesn't seem to say anything to support your conclusion. It only says that the value of the MAILTO variable controls where the mail is sent, not how the value of the variable is determined, or how long an assignment is in effect.
    – ilkkachu
    Feb 10 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.