[英]Run sh file from php with cron
I have an sh file with file-removing commands. 我有一个带有文件删除命令的sh文件。
I run it from php like this: 我从php这样运行它:
shell_exec("sudo -n ./truncatefiles.sh 2>&1");
Thats works fine if I open the PHP file from browser, but doesnt work from scheduled cron tab. 如果我从浏览器中打开PHP文件,那可以正常工作,但不能通过计划的cron选项卡工作。
PHP user: www-data
PHP用户:
www-data
If i run whoiami
from cron, returns same: www-data 如果我从cron运行
whoiami
,则返回相同内容:www-data
I added this to my visudo: 我将此添加到我的visudo中:
www-data ALL=(ALL) NOPASSWD: /www/sites/..../importscript/truncatefiles.sh
Shell exec for this sh file returns (from cron): 此sh文件的Shell exec从cron返回:
sudo: sorry, a password is required to run sudo sudo:对不起,运行sudo需要密码
Why works it dirrefent way in cron? 为什么在cron中以间接方式工作?
What should I do for get it work? 我应该怎么做才能使其正常工作?
PLease try to do the following, Try to log your output from crotab to a file, * * myscript.php >> /var/log/myjob.log 2>&1 This way you can debug your script. 请尝试执行以下操作,尝试将crotab的输出记录到文件中,* * myscript.php >> /var/log/myjob.log 2>&1这样就可以调试脚本了。 1. Also the check the user and permissions for your shell script, php file.
1.还要检查您的Shell脚本php文件的用户和权限。 2. try with sudo crotab -e
2.尝试使用sudo crotab -e
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.