若文件存在,debian将使用crontab重新启动


debian restart with crontab if file exists

我有这个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中,什么也没发生。我做错了什么?

也许您的crontab没有PATH变量集。为命令sh设置PATH变量或使用完整路径,如/bin/sh

我改变了做这件事的方式。

我在/etc/sudoers中添加了一行:

%www-dataALL=NOPASSWD: /sbin/reboot

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

exec("sudo /sbin/reboot");