【问题标题】:User not allowed to use crontab用户不允许使用 crontab
【发布时间】:2022-01-06 20:57:55
【问题描述】:

我想每天编辑 cron 选项卡以删除/添加一些作业 .. 所以我添加了 cron 作业(助手作业)来运行 php 脚本来处理这些编辑。

当我通过浏览器运行此脚本时工作正常.. 但是当它使用未运行的辅助作业运行时,我从 cpanel 收到带有此错误的通知邮件:

请注意,我使用 C-Panel 的共享主机计划,所以我没有 root 访问权限.. 但是从浏览器运行时代码运行良好。

错误:

You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information
You (dcfn35c8st1b) are not allowed to use this program (crontab)
See crontab(1) for more information

PHP 脚本:

exec('crontab -l', $crontab);
$record_found = false;
foreach($crontab as $key => $value){
    if(strpos($value, 'record_extra.php') !== false){
        //echo $key . ' ' . $value . '<br>';
        unset($crontab[$key]);
        $record_found = true;
    }
        if(strpos($value, 'record.php') !== false){
        //echo $key . ' ' . $value . '<br>';
        unset($crontab[$key]);
    }
}
if($record_found){
    file_put_contents('/tmp/crontab.txt', arrayToString($crontab) . $firstJob.PHP_EOL);
    if(exec('crontab /tmp/crontab.txt')){
        //echo 'success <br>'; 
    } else {
        //echo 'error <br>'; 
    }
    $output = shell_exec('crontab -l');
    file_put_contents('/tmp/crontab.txt', $output . $secondJob.PHP_EOL);
    if(exec('crontab /tmp/crontab.txt')){
        //echo 'success <br>'; 
    } else {
        //echo 'error <br>'; 
    }
} else {
    $output = shell_exec('crontab -l');
    file_put_contents('/tmp/crontab.txt', $output . $firstJob.PHP_EOL);
    if(exec('crontab /tmp/crontab.txt')){
        //echo 'success <br>'; 
    } else {
        //echo 'error <br>'; 
    }
    $output = shell_exec('crontab -l');
    file_put_contents('/tmp/crontab.txt', $output . $secondJob.PHP_EOL);
    if(exec('crontab /tmp/crontab.txt')){
        //echo 'success <br>'; 
    } else {
        //echo 'error <br>'; 
    }
}

需要你的帮助。 提前致谢。

【问题讨论】:

  • 所以很可能是权限问题。为什么你从脚本运行 crontab 而不是只编辑 /etc/cron.daily 文件?
  • 这似乎是一个类似 SELinux 或 AppArmor 的安全程序。您需要找到您的系统正在使用哪一个并授予用户 dcfn35c8st1b 适当的权限。
  • 请注意我与 C-Panel 共享托管计划,所以我没有 root 访问权限.. 但是从浏览器运行时代码工作正常
  • 即使你的 web 服务器 PHP 进程在与命令行 PHP 相同的用户下运行(我不知道是不是这样),权限也可以设置不同。

标签: php cron cron-task


【解决方案1】:

似乎不允许用户运行 crontab。查看文件“/etc/cron.allow”和“/etc/cron.deny”。如果 cron.allow 存在,则只有该列表中的用户可以使用 crontab。 cron.deny 中的用户,不能使用。如果两者都不存在,则只有 root 用户可以使用 crontab。

【讨论】:

  • 不是真的,如果这些都不存在 - 所有用户都可以使用它
  • @FlashThunder 要允许所有用户,您应该有一个空的 cron.deny 文件。但我相信它应该存在。
  • 请注意我与 C-Panel 共享托管计划,所以我没有 root 访问权限..但是从浏览器运行时代码工作正常
猜你喜欢
  • 2020-01-15
  • 2016-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多