PHP(Apache) 不执行 BASH 命令 (At + Wget)

标签 php linux apache ubuntu at-job

所以,伙计们,我有以下代码:

<?php
  $url  = "http://example.com/filetorun.php";
  $time = date('g:i A d.m.Y', $res['sometime']); 
  echo `echo "wget --spider {$url}" | at -M {$time}`;
?>

主要思想是在特定时间获取一些url,为我执行一些有用的操作。

终端会发生什么?

当我运行这个 bash 代码时。它给我这样的输出效果很好:
warning: commands will be executed using /bin/sh
job 59 at Mon Jan 13 17:12:00 2020

当我运行我的 php 脚本时,/var/log/apache2/error.log 会发生什么?

它得到这个输出。

atq怎么了?

只有当我通过终端创建作业时,我才能在那里看到作业。当我从 php 脚本创建它时,我不能这样做。

我试图做什么?

我将用户添加到/etc/at.allow 并从/etc/at.deny 中删除它们

最佳答案

没有太多细节可以继续,但我将您的注意力引向 at 的这个要求:

The value of the SHELL environment variable at the time of at invocation will determine which shell is used to execute the at job commands. If SHELL is unset when at is invoked, the user's login shell will be used; otherwise, if SHELL is set when at is invoked, it must contain the path of a shell interpreter executable that will be used to run the commands at the specified time.



您的 Web 服务器用户是否定义了登录 shell? getent passwdgrep /etc/passwd来确定。无论如何,我建议将 shell 设置为在命令本身中使用,以防止有人更改调用用户的默认 shell 的问题。

如果这不是问题,我们可能需要更多细节。

关于PHP(Apache) 不执行 BASH 命令 (At + Wget),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59719218/

相关文章:

php - 按条目字段将 mysql 获取的结果显示到按行组织的表中?

python - cx_Oracle python 模块在 Linux 中的安装

apache - 如何从Powershell输出中删除多余的空格?

apache - debian上的golang/apache/cgi-apache重定向停止工作

python - Django 不提供管理静态文件(Apache、mod_wsgi)

php zip 存档内存、ram 和最大文件大小

php - PHP警告:mysql_fetch_array()期望参数1

php - 尝试使用 PHP 将数据库中的图像插入新闻博客每个条目上方

c++ - 打印unicode字符c++ linux

Linux 使用 xmodmap 交换 alt 和 meta 中断 '5'(需要管理员注意)