简体   繁体   中英

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.

What happens in the terminal?

When I run this bash code. 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?

It gets this output.

What's about 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.

What have I tried to do?

I added users to /etc/at.allow and deleted them from /etc/at.deny

Not a lot of detail to go on, but I direct your attention to this requirement of 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.

Does your web server user have a login shell defined? getent passwd or grep /etc/passwd to determine. 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.

If this is not the issue, we probably need more detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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