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

只有当我看到这一点时,我才明白为什么在fast admin中推荐的计划任务格式是

[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

您可以将/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.

问:我有一些cron作业在Linux系统上彻夜运行。如果需要查看,每个作业都会将信息输出到一个文本文件中。有些是为了通过mail命令发送电子邮件而编写的。

[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.

但是,因为我将这些脚本放在新系统上,并将它们添加到crontabb中,所以我收到了有关我运行的每个作业的电子邮件。从根目录发送的电子邮件太多。有没有办法阻止这种行为?

[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?

答:Crond通常在执行cron作业时发送电子邮件。它使用/etc/crontab中的mailto变量来确定谁接收电子邮件,默认情况下是根用户。有几种方法可以阻止这种行为。

[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变量更改为空白。

您可以编辑/etc/crontab文件,并将mailto变量更改为:

[En]

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

MAILTO=””

这将有效地禁用来自cron守护进程的所有电子邮件。然后,您可以在脚本中决定是使用mailx命令还是您选择的命令来发送消息。

[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.

这不是我的首选方法,因为我希望在cronjob中出现错误时接收电子邮件。

[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 定时任务,任务失败后发邮件问题

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/7051/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部