【问题标题】:debian restart with crontab if file exists如果文件存在,则使用 crontab 重新启动 debian
【发布时间】:2015-05-23 19:52:23
【问题描述】:

我有这个 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 (echo $PATH)?
  • @Sverri:你应该停止在 cmets 中发布其他人的答案。
  • @cari 你看到我评论末尾的问号了吗?上次我检查,答案没有问号...

标签: php shell cron debian crontab


【解决方案1】:

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

【讨论】:

  • 你应该避免假设的东西。如果您需要更多信息来回答问题,请使用 cmets 区域询问更多信息。
【解决方案2】:

我改变了做事的方式。

我添加到/etc/sudoers这一行:

%www-dataALL=NOPASSWD: /sbin/reboot

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

exec("sudo /sbin/reboot");

【讨论】:

    猜你喜欢
    • 2018-03-27
    • 1970-01-01
    • 2013-07-14
    • 2014-10-13
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    相关资源
    最近更新 更多