如果文件存在,则使用crontab重新启动debian

时间:2015-03-20 11:55:48

标签: php shell cron debian crontab

我有这个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中,没有任何反应。 我做错了什么?

2 个答案:

答案 0 :(得分:0)

也许你的crontab没有PATH变量集。 为命令sh设置PATH变量或使用像/ bin / sh

这样的完整路径

答案 1 :(得分:0)

我改变了我的方式。

我添加了/etc/sudoers行:

%www-dataALL=NOPASSWD: /sbin/reboot

在我的php文件中我正在做:

exec("sudo /sbin/reboot");