# linux crontab 定时任务，任务失败后发邮件问题

linux crontab 定时任务，任务失败后发邮件问题
https://www.cnblogs.com/sgj123/p/13203481.html

crontab定时任务不执行，并且没有收到错误信息邮件
https://blog.csdn.net/sd4493091/article/details/83345661
https://blog.csdn.net/kirrin/article/details/79884897
https://www.cnblogs.com/worez/p/4999991.html

[En]

It was only when I saw this that I understood why the format of scheduled tasks recommended in fastadmin is

* * * * * /usr/bin/php /www/yoursite/public/index.php /addons/crontab/autotask/index > /dev/null  2>&1 &


2>&1 的意思就是将标准错误重定向到标准输出。这里标准输出已经重定向到了 /dev/null。那么标准错误也会输出到/dev/null

[En]

You can think of / dev/null as a “black hole”. It is equivalent to a write-only file. Everything written to it will be lost forever. If you try to read from it, you can’t read anything.

[En]

Occasionally & can be added to the end of the command to indicate that the program is allowed to execute in the background.

[En]

Q: I have some cron jobs that run overnight on the Linux system. If you need to view it, each of these jobs outputs the information to a text file. Some are written to send e-mail through the mail command.

[En]

However, because I put these scripts on the new system and added them to crontab, I received emails about each job I ran. Too many emails are sent from the root directory. Is there any way to stop this behavior?

[En]

Answer: Crond usually sends an email when executing a cron job. It uses the MAILTO variable in / etc / crontab to determine who receives the e-mail, which by default is root. There are several ways to stop this behavior.

1.将MAILTO变量更改为空白。

[En]

You can edit the / etc / crontab file and change the MAILTO variable to:

MAILTO=””

[En]

This effectively disables all e-mail from the cron daemon. You can then decide in the script to use the mailx command or the command of your choice to send the message.

[En]

This is not my preferred method, because I want to receive email when there is an error in cronjob.

Original: https://www.cnblogs.com/bluestorm/p/15985800.html
Author: petercao
Title: linux crontab 定时任务，任务失败后发邮件问题

(0)