2015年11月8日 星期日

[Linux 常見問題] Disable The Mail Alert By Crontab Command On a Linux or Unix-like Systems

Source From Here 
Question 
How do I to disable the mail alert send by crontab? When my job is executed and the jobs cannot run normally it will sent an email to root. Why do I receive e-mails to my root account from cron? How can I prevent this? How can I disable email alert sent by cron jobs on a Linux or Unix-like systems? 

How-To 
The crontab command is used to maintain crontab files for individual users. By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append following strings at the end of crontab entry. 

Cron job prevent the sending of errors and output 
To prevent the sending of errors and output, add any one of the following at the end of the line for each cron job to redirect output to /dev/null. For example: 
# crontab -e
  1. */10 * * * * /root/test.sh > /dev/null 2>&1  

Set MAILTO variable 
You can set MAILTO="" variable at the start of your crontab file. This will also disable email alert. Edit/Open your cron jobs: 
# crontab -e
  1. MAILTO=""  
  2. */10 * * * * /root/test.sh > /dev/null 2>&1  

Save and close the file. 

Supplement 
鳥哥 Linux 私房菜 - 第十五章、例行性工作排程(crontab)

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...