CakePHP Shell Cron 电子邮件错误

发布于 2024-10-30 08:09:20 字数 634 浏览 11 评论 0原文

我正在使用 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

这会将结果输出到日志文件中,但我希望在出现错误时收到电子邮件,以便我可以尝试解决问题。 我尝试了以下方法,但没有成功。

  1. 如果我删除>> /path/to/log/file.log 然后,即使成功运行也会通过电子邮件发送。
  2. > /dev/null,我的假设是它将成功发送到 /dev/null 并将错误发送到电子邮件。
  3. 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.

  1. If I remove the >> /path/to/log/file.log then even the successful run is emailed.
  2. > /dev/null, my assumption was it would send a successful to /dev/null and error to email.
  3. 1> /dev/null, tried another variation of 2

Any help is appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七月上 2024-11-06 08:09:20

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 the mail command, then you set another cron job following the first in time which then simply runs a if [ -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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文