5

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

 3 years ago
source link: https://www.lujun9972.win/blog/2019/06/23/%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9crontab%E4%BB%BB%E5%8A%A1%E7%BB%93%E6%9E%9C%E7%9A%84%E9%82%AE%E4%BB%B6%E6%8E%A5%E6%94%B6%E4%BA%BA/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

如何更改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,但其值为空,则表示不将结果通过邮件进行通知。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK