简体   繁体   English

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

[英]PHP(Apache) doesn't execute BASH command (At + Wget)

So, guys, I have the following code:所以,伙计们,我有以下代码:

<?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}`;
?>

The main idea is to wget some url at the specific time to perform some useful operations for me.主要思想是在特定时间 wget 一些 url 为我执行一些有用的操作。

What happens in the terminal?在终端会发生什么?

When I run this bash code.当我运行这个 bash 代码时。 It works well giving me the output like this:给我这样的输出效果很好:

warning: commands will be executed using /bin/sh
job 59 at Mon Jan 13 17:12:00 2020

What happens in /var/log/apache2/error.log when I run my php script?当我运行我的 php 脚本时,/var/log/apache2/error.log 中会发生什么?

It gets this output.它得到这个输出。

What's about atq? atq呢?

I can see the job there only when I create it via the Terminal.只有当我通过终端创建它时,我才能在那里看到工作。 When I create It from the php-script, I can not do that.当我从 php 脚本创建它时,我不能这样做。

What have I tried to do?我试图做什么?

I added users to /etc/at.allow and deleted them from /etc/at.deny我将用户添加到 /etc/at.allow 并从 /etc/at.deny 中删除它们

Not a lot of detail to go on, but I direct your attention to this requirement of at :没有太多细节要讲,但我将您的注意力引向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.调用 at 时 SHELL 环境变量的值将决定使用哪个 shell 来执行 at 作业命令。 If SHELL is unset when at is invoked, the user's login shell will be used;如果在调用 at 时未设置 SHELL,则将使用用户的登录 shell; 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.否则,如果在调用 at 时设置了 SHELL,则它必须包含将用于在指定时间运行命令的 shell 解释器可执行文件的路径。

Does your web server user have a login shell defined?您的 Web 服务器用户是否定义了登录 shell? getent passwd or grep /etc/passwd to determine. getent passwdgrep /etc/passwd来确定。 Regardless, I suggest setting the shell to use in the command itself, to prevent issues where someone chnahes the default shell of the invoking user.无论如何,我建议将 shell 设置为在命令本身中使用,以防止有人更改调用用户的默认 shell 的问题。

If this is not the issue, we probably need more detail.如果这不是问题,我们可能需要更多细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM