我有这个scipt:
#!/bin/bash
while true
do
if [ -f /opt/command/command.txt ]; then
chmod 777 /opt/command/command.txt
rm /opt/command/command.txt
reboot
fi
done
在我的crontab中我有:
@reboot sh /root/reboot.sh
使用此php代码创建文件:
$fh = fopen("/opt/command/command.txt", 'w');
fwrite($fh, "reboot");
fclose($fh);
因此,如果我手动运行sh reboot.sh
,则此代码有效。
但在crontab中,没有任何反应。
我做错了什么?
答案 0 :(得分:0)
也许你的crontab没有PATH变量集。 为命令sh设置PATH变量或使用像/ bin / sh
这样的完整路径答案 1 :(得分:0)
我改变了我的方式。
我添加了/etc/sudoers
行:
%www-dataALL=NOPASSWD: /sbin/reboot
在我的php文件中我正在做:
exec("sudo /sbin/reboot");