如何在 cron 作业中设置文件

发布于 2024-07-25 02:03:58 字数 249 浏览 1 评论 0原文

我需要每分钟运行一个 php 文件,所以我尝试从 cpanel 设置一个 cronjob 但它发送邮件时显示消息“无法打开输入文件:”

我的 php 文件位于 public_html/schoolerp/cron.php

我做了:

/usr/local/bin/php -f /public_html/schoolerp/cron.php

Am我做错了请告诉我是否设置正确,如果我错了请帮助我纠正......

I need to run a php file every minute so I tried to set a cronjob from the cpanel
but it's sending mail with the message "could not open the input file:"

My php file is inside public_html/schoolerp/cron.php

I did:

/usr/local/bin/php -f /public_html/schoolerp/cron.php

Am I doing something wrong please tell me if I am setting it right, and if I am wrong please help me correct it ...

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

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

发布评论

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

评论(2

聽兲甴掵 2024-08-01 02:03:58
  • 使用绝对路径
  • 确保脚本是
    可访问,检查路径上文件/目录的访问权限
  • cron 默认情况下将采取所有
    脚本的输出并将其发送到
    您的电子邮件

您可以将命令的输出重定向到文件或 /dev/null 以防止 cron 发送电子邮件。 我建议重定向到本地文件以供将来参考,这有利于调试和出现问题时。

我认为应该这样做:

/usr/local/bin/php -f /public_html/schoolerp/cron.php > /logs/mylog.txt 2>&1

重定向到 mylog.txt 文件并将 stderror 附加到 stdout,以便 stderror 和 stdout 都在日志文件中。

  • Use absolute paths
  • Make sure that the script is
    accessible, check access permissions of file/directories on path
  • cron by default will take all the
    output of your script and send it to
    your email

You can redirect the output of your command to file or /dev/null to prevent cron from sending email. I would suggest redirect to local file for future references, it's good for debugging and when something goes wrong.

I think something like this should do:

/usr/local/bin/php -f /public_html/schoolerp/cron.php > /logs/mylog.txt 2>&1

Redirect to mylog.txt file and append stderror to stdout so that both stderror and stdout is in log file.

绅士风度i 2024-08-01 02:03:58

不确定这是否是一个完整的修复,但您正在使用“/public_html/schoolerp/cron.php”的绝对路径,而这似乎不太可能是正确的。 您可能正在寻找“public_html/schoolerp/cron.php”的相对路径(注意前面缺少“/”)。 不过,您可能只想使用从文件系统根目录开始的正确绝对路径。

Not sure if this is a complete fix, but you are using absolute pathing for '/public_html/schoolerp/cron.php', when that doesn't seem very likely to be correct. You might be looking for a relative path of 'public_html/schoolerp/cron.php' (note the lack of preceding '/'). You may just want to use the proper absolute path starting from the root of the filesystem though.

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