如何在cron作业中设置文件

时间:2022-06-07 09:15:08

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:"

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

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

我的php文件在public_html / schoolerp / cron.php中

I did:

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

/ 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 ...

我做错了什么,请告诉我,如果我做对了,如果我错了,请帮我纠正一下......

2 个解决方案

#1


  • 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
  • 默认情况下,cron将获取脚本的所有输出并将其发送到您的电子邮件

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.

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

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.

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

#2


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.

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

#1


  • 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
  • 默认情况下,cron将获取脚本的所有输出并将其发送到您的电子邮件

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.

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

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.

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

#2


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.

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