简体   繁体   English

Crontab无法执行PHP脚本。 错误的解释器:没有这样的文件或目录

[英]Crontab unable to execute PHP script. bad interpreter: No such file or directory

Trying to use Crontab to execute commands at regular intervals. 尝试使用Crontab定期执行命令。 But crontab keeps giving the error: 但是crontab不断给出错误:

/bin/sh: /var/www/html/Scripts/lib/Tasks.php: /usr/bin/php^M: bad interpreter: No such file or directory / bin / sh:/var/www/html/Scripts/lib/Tasks.php:/ usr / bin / php ^ M:错误的解释器:无此类文件或目录

Tasks.php: Tasks.php:

#!/usr/bin/php
<?php
//scripts
?>

I feel like my Shebang is messed up. 我觉得我的Shebang搞砸了。 The main php file appears to be present in /usr/bin/php but I keep getting the error. 主要的php文件似乎存在于/ usr / bin / php中,但我一直收到错误消息。 I have been trying other shebangs from other posts but most of them are not using the combination of Centos6 php5 and apache. 我一直在尝试其他帖子中的其他shebang,但其中大多数都没有使用Centos6 php5和apache的组合。 I just need to execute this php script every few min. 我只需要每隔几分钟执行一次此php脚本。

In php file shebang operator will not work as per my understanding. 根据我的理解,在php文件中,shebang运算符将不起作用。

You can rewrite crontab as below: 您可以按以下方式重写crontab:

* * * * * /usr/bin/php /var/www/html/Scripts/lib/Tasks.php

You can change crontab frequency as per you need. 您可以根据需要更改crontab频率。 Also please verify if php is at right place with below command: 另外,请使用以下命令验证php是否在正确的位置:

which php

Thanks. 谢谢。

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

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