简体   繁体   English

PHP exec无法通过crontab(cronjobs)工作,但可以通过控制台正常工作

[英]PHP exec not working via crontab (cronjobs) but works fine via console

I try to restart my LTE modem via cron. 我尝试通过cron重新启动LTE调制解调器。 I have a PHP file (restart.php) with exec() function: 我有一个带有exec()函数的PHP文件(restart.php):

exec('usb_modeswitch -R -v 12d1 -p 1436');

It works fine if I type in console (as root): 如果我以根用户身份输入控制台,则效果很好:

php restart.php

But not works via crontab (for root): 但不适用于crontab(对于root用户):

*/10 * * * * php /var/www/html/modem/restart.php

I have 777 permissions for restart.php file and the path is ok. 我具有restart.php文件的777权限,并且路径正常。

What is wrong? 怎么了? And how I can fix it? 以及我该如何解决? Any ideas? 有任何想法吗?

Please, help 请帮忙

Try to use full path in crontab for php and in php script. 尝试在crontab中为php和php脚本使用完整路径。 You can find where is php binary by this command: 您可以通过以下命令找到php二进制文件在哪里:

whereis php

I added a full path to usb_modeswitch and it solved my problem: 我向usb_modeswitch添加了完整路径,它解决了我的问题:

exec('/usr/sbin/usb_modeswitch -R -v 12d1 -p 1436');

Rob Ruchte, Thank u for solution Rob Ruchte,谢谢您的解决方案

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

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