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

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

问题描述:

I try to restart my LTE modem via cron. I have a PHP file (restart.php) with exec() function:

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

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

I have 777 permissions for restart.php file and the path is ok.

What is wrong? And how I can fix it? Any ideas?

Please, help

我尝试通过cron重启我的LTE调制解调器。 我有一个带有exec()函数的PHP文件(restart.php): p>

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

如果我输入控制台(以root用户身份),它可以正常工作: p>

  php restart.php 
  code>  
 
 

但不能通过crontab工作(对于root): p>

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

我对restart.php文件有777权限,路径正常。 p>

有什么问题 ? 我怎么解决它? 有任何想法吗? p>

请帮助 p> div>

I added a full path to usb_modeswitch and it solved my problem:

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

Rob Ruchte, Thank u for solution

Try to use full path in crontab for php and in php script. You can find where is php binary by this command:

whereis php