如果命令输出重定向到日志文件,则cron停止发送错误邮件

问题描述 投票:0回答:1

我对来自cron的错误邮件有疑问如果我创建两个执行相同的perl脚本的作业,一个作业重定向到/ dev / null或一个日志文件,而一个没有重定向,我只会收到一个错误邮件,而没有重定向]

/etc/cron.d/test-cron

MAILTO="[email protected]"
*   *   *   *   *   root    /root/test.sh > /dev/null
*   *   *   *   *   root    /root/test.sh
/root/test.sh

#!/usr/bin/perl
use strict;

print "test\n";
exit 1;

cron和postfix的syslog输出

May 18 19:14:01 cron-master CRON[31428]: (root) CMD ([31436] /root/test.sh)
May 18 19:14:01 cron-master CRON[31428]: (CRON) error (grandchild #31436 failed with exit status 1)
May 18 19:14:01 cron-master CRON[31428]: (root) END ([31436] /root/test.sh)
May 18 19:14:01 cron-master CRON[31429]: (root) CMD ([31439] /root/test.sh > /dev/null)
May 18 19:14:01 cron-master CRON[31429]: (CRON) error (grandchild #31439 failed with exit status 1)
May 18 19:14:01 cron-master CRON[31429]: (root) END ([31439] /root/test.sh > /dev/null)
May 18 19:14:01 cron-master postfix/pickup[28859]: 5537251A9: uid=0 from=<root>
May 18 19:14:01 cron-master postfix/cleanup[30966]: 5537251A9: message-id=<20200518191401.5537251A9@[email protected]>
May 18 19:14:01 cron-master postfix/qmgr[143]: 5537251A9: from=<[email protected]>, size=674, nrcpt=1 (queue active)
May 18 19:14:01 cron-master postfix/smtp[30968]: 5537251A9: to=<[email protected]>, relay=smtp.example.com[80.50.67.97]:587, delay=0.42, delays=0.02/0/0.32/0.09, dsn=2.0.0, status=sent (250 Requested mail action okay, completed: id=1Ma1oK-1jXP8H2tyW-00W08q)
May 18 19:14:01 cron-master postfix/qmgr[143]: 5537251A9: removed
  • cron-> 3.0pl1-136ubuntu1
  • 后缀-> 3.4.10-1ubuntu1
  • OS->最新的Ubuntu 20.04 docker映像(ubuntu:focal-20200423)
  • Docker端点-> / usr / sbin / cron -f -l -L 15

我对来自cron的错误邮件有问题,如果我创建了两个执行相同的perl脚本的作业,一个作业重定向到了/ dev / null或一个日志文件,而一个没有重定向,我只会收到一条错误邮件...

linux cron postfix-mta
1个回答
0
投票

您可以使用tee命令来“分叉”标准输出。

© www.soinside.com 2019 - 2024. All rights reserved.