如果文件存在,debian 用 crontab 重启
debian restart with crontab if file exists
我有这个脚本:
#!/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");
我有这个脚本:
#!/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");