我有几个cron作业每天从我的cPanel运行。这意味着99%的时间我收到每日电子邮件说一切正常 - 备份没问题,xml导入正常等等。
但我需要的是当cron的结果不正常时的通知 - 即不正常。我已尝试在Outlook中制定规则,但我无法使其发挥作用。
这是我的一个朋友:
30 2 * * * /usr/local/bin/php /home/xx/public_html/administrator/xx/xx/backup.php -profile=1 -description="Backup"
我知道'Bash'有可能,但不是如何实际使用它。
任何人都有好主意吗?
投入赞赏。
答案 0 :(得分:0)
您可以在作业周围编写一个包装器,并从cron中调用包装器。
示例:
#!/usr/bin/env ksh # # Wrapper around a backup script. # # Redirecting all output to a log file # In this case to /home/xx/public_html/administrator/xx/xx/backup_job.log # # Lets log the start date of the job in a log file # echo "Starting backup job at `/bin/date`" >> /home/xx/public_html/administrator/xx/xx/backup_job.log # # start the backup # /home/xx/public_html/administrator/xx/xx/backup.php >> /home/xx/public_html/administrator/xx/xx/backup_job.log # # The backup job should have set a return value (0 or non-zero). # # If it is non-zero then there was an error. Lets send a warning mail about it # # if [[ $? -ne 0 ]]; then /bin/mail admin > /var/adm/backup_log # # Exit with a 0 value. That should indictate that this job (the wrapper) worked fine # Usually this means cron does not have to send a mail. (But then, we already took care # of warning mails on our won if there was an error # exit 0