暗无天日

=============>DarkSun的个人博客

如何更改crontab任务结果的邮件接收人

crond 的手册说明中有这么一段话

Cron  examines  all stored crontabs and checks each job to see if it needs to be run in the current minute.  
When executing commands, any output is mailed to the owner of the crontab (or to the user specified in the MAILTO environment variable in the crontab, if such exists).  
Any job output can also  be  sent  to syslog by using the -s option.

也就是说,若想更改 crontab 的邮件接收人,只需要将 MAILTO 环境变量设置成其他用户即可,比如

MAILTO=root
* * * * *  command to be executed

会将命令执行结果发送给 root 而不是 crontab任务所有者

如果设置了 MAILTO,但其值为空,则表示不将结果通过邮件进行通知。