CakePHP Shell Cron 电子邮件错误
我正在使用 CakePHP 1.3,并且我能够使用 CakePHP Book。
*/5 * * * * /full/path/to/cakeshell myshell myparam -cli /usr/bin -console /cakes/1.2.x.x/cake/console -app /full/path/to/app >> /path/to/log/file.log
这会将结果输出到日志文件中,但我希望在出现错误时收到电子邮件,以便我可以尝试解决问题。 我尝试了以下方法,但没有成功。
- 如果我删除>> /path/to/log/file.log 然后,即使成功运行也会通过电子邮件发送。
- > /dev/null,我的假设是它将成功发送到 /dev/null 并将错误发送到电子邮件。
- 1> /dev/null,尝试了 2 的另一种变体
如有帮助,我们将不胜感激。
谢谢
I am using CakePHP 1.3 and I was able to successfully able setup the cron job to run shells using the example that was given in the CakePHP Book.
*/5 * * * * /full/path/to/cakeshell myshell myparam -cli /usr/bin -console /cakes/1.2.x.x/cake/console -app /full/path/to/app >> /path/to/log/file.log
This outputs the results into a log file but I want to receive email when there is an error so I can try to resolve the problem.
I tried the following with no luck.
- If I remove the >> /path/to/log/file.log then even the successful run is emailed.
- > /dev/null, my assumption was it would send a successful to /dev/null and error to email.
- 1> /dev/null, tried another variation of 2
Any help is appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Huseyin,
那么这不是 CakePHP 错误,并且可能是一个更适合服务器故障的问题,因为您将编写解决方案的脚本。
Bash 的内置工具足以胜任这项任务,请尝试Linux 文档项目有关 shell 脚本编写的简洁介绍性教程和
#男子bash
。您的解决方案基本上必须使用临时文件或变量来存储上次 cron 作业运行的输出。如果出现错误:
cat THE_TMP_FILE | mail -s “来自 Huseyin 服务器的错误” huseyin@fancy_domain.com
否则:
cat THE_TMP_FILE >>> blah.blah.log
不幸的是,您需要一个可用的 MTA,才能执行
mail
命令。如果您无权访问mail
命令,那么您可以在第一个 cron 作业之后设置另一个 cron 作业,然后简单地运行if [ -e THE_FILE_CONTAINING_THE_LAST_ERROR];然后 { echo $(cat THE_FILE_CONTAINING_THE_LAST_ERROR); rm -v THE_FILE... ;} ; fi
当然这不是工作代码,但非常接近,所以你会明白的。
Huseyin,
This is not a CakePHP error then, and is maybe a question better suited for serverfault, as you would script your solution.
Bash's built-in facilities are up to the task, try The linux documentation project's neat introductory tutorials on shell scripting and
#man bash
.Your solution basically has to use a temporary file or variable in which you store the output of the last cron job run. If there is an error:
cat THE_TMP_FILE | mail -s "Error from Server Huseyin's server" huseyin@fancy_domain.com
else:
cat THE_TMP_FILE >> blah.blah.log
Unfortunatly, you need a MTA available, in order to make the
mail
command. If you do not have access to themail
command, then you set another cron job following the first in time which then simply runs aif [ -e THE_FILE_CONTAINING_THE_LAST_ERROR]; then { echo $(cat THE_FILE_CONTAINING_THE_LAST_ERROR); rm -v THE_FILE... ;} ; fi
Of course this is not working code, but pretty close, so you'll get the idea.