简体   繁体   English

Cron运行脚本,但是代码不执行

[英]Cron runs script but code doesn't execute

I have a cronjob that looks like this: 我有一个cronjob看起来像这样:

30-59/1 13 * * 1-5 /usr/bin/php /home/myproject/main/logic.php 2>&1 >>/home/myproject/main/cronlog.txt

I can run the script fine from the command line. 我可以从命令行正常运行脚本。

And I can see it being ran in syslog. 我可以看到它正在syslog中运行。

grep CRON /var/log/syslog

Apr  5 18:51:01 ip-x-x-x-x CRON[30277]: (ubuntu) CMD (/usr/bin/php /home/myproject/main/logic.php 2>&1 /home/myproject/main/cronlog.txt)

Permissions: 权限:

-rwxrwxr-x 1 root root 4791 Apr  5 18:31 logic.php

In my php file: 在我的php文件中:

require '/home/myproject/main/data.php';
require '/home/myproject/vendor/autoload.php';

But the code in my script is not actually executing. 但是脚本中的代码并未真正执行。

Any ideas what I'm doing wrong here? 有任何想法我在这里做错了吗?

You sending stderr to stdout, but your not sending stdout anywhere. 您将stderr发送到stdout,但没有在任何地方发送stdout。 Need to put the > in front of your file. 需要在文件前加上>。

30-59/1 13 * * 1-5 /usr/bin/php /home/myproject/main/logic.php 2>&1 >/home/myproject/main/cronlog.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM