为什么我的某些 cron 作业没有发送守护进程电子邮件?

为什么我的某些 cron 作业没有发送守护进程电子邮件?

我的 crontab:

PATH=/sbin:/bin:/usr/sbin:/usr/bin
[email protected]
HOME=/
LD_LIBRARY_PATH=/usr/local/lib/
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR
#sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
05 01 * * * /root/backup_scripts/run_backups.sh
45 03 * * * /root/backup_scripts/new_scripts/run.sh> "/root/backup_scripts/new_scripts/$(date).run.log" 2>&1

我确实收到了有关 run_backups.sh 作业的守护进程电子邮件

我没有收到有关 run.sh 作业的守护进程电子邮件,但我验证了它确实在运行

这是 run_backups.sh 的守护进程电子邮件:

    from    Cron Daemon <[email protected]>
to  [email protected]
date    Thu, Sep 30, 2010 at 2:22 AM
subject Cron <root@aapsan01> /root/backup_scripts/run_backups.sh
mailing list    <admins.boingoboingo.com> Filter messages from this mailing list
mailed-by   boingoboingo.com
hide details 2:22 AM (7 hours ago)
[09/30/10 01:05:01] mounting the usb drive
[09/30/10 01:05:09] usbdrive1 is ready.
[blah]blah, blah blah.
[09/30/10 06:41:51] finished syncing drives.
[09/30/10 06:41:53] usbdrive1 was disconnected.

答案1

电子邮件是数据从您的 cron 作业发送到 STDOUT 或 STDERR 的结果。有问题的 cron 作业已将两者都重定向到日志文件。

> "/root/backup_scripts/new_scripts/$(date).run.log" 2>&1
^ redirect STDOUT to file ^                          ^^^^ redirect STDERR to SDTOUT 

答案2

将 的标准输出重定向run.sh到之后/root/backup_scripts/new_scripts/$(date).run.log,只剩下错误输出需要重定向到标准输出。难道 根本run.sh就不会产生任何错误?

如果您想查看标准输出,run.shtee可以将其保存到文件中。

45 03 * * * /root/backup_scripts/new_scripts/run.sh | tee "/root/backup_scripts/new_scripts/$(date).run.log" 2>&1

相关内容