![为什么我的某些 cron 作业没有发送守护进程电子邮件?](https://linux22.com/image/1252244/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E7%9A%84%E6%9F%90%E4%BA%9B%20cron%20%E4%BD%9C%E4%B8%9A%E6%B2%A1%E6%9C%89%E5%8F%91%E9%80%81%E5%AE%88%E6%8A%A4%E8%BF%9B%E7%A8%8B%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6%EF%BC%9F.png)
我的 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.sh
也tee
可以将其保存到文件中。
45 03 * * * /root/backup_scripts/new_scripts/run.sh | tee "/root/backup_scripts/new_scripts/$(date).run.log" 2>&1