-1

I have a job which created by PHP script running as www (nginx)

31      2014-06-09 19:08 a www

After the time passed, the job is executed but nothing happens.

But if i run it as a root,

32      2014-06-09 19:09 a root

the job is executed and i can get the result.

Any idea how to allow www run the at job?

EDIT: This is how my php script executing at command

$command = 'echo "/usr/bin/php -q /home/wwwroot/cron/poster.php 8137660219700061402317686 1" | at now + 1 minute';

shell_exec($command);

There will be a job listed, created by www

atq -c 48

More info regarding the at job,

48      2014-06-09 21:08 a www

[root@914K7 ~]# at -c 48
#!/bin/sh
# atrun uid=501 gid=501
# mail www 0
umask 22
USER=www; export USER
PWD=/home/wwwroot/ajax; export PWD
SHLVL=1; export SHLVL
HOME=/home/www; export HOME
cd /home/wwwroot/ajax || {
     echo 'Execution directory inaccessible' >&2
     exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER509e6acf'
/usr/bin/php -q /home/wwwroot/cron/poster.php 81376602197000614023176 1

marcinDELIMITER509e6acf

But after time passed, the job is gone meaning it has been executed, but I dont receive any output from the script.

If I manually create at job through command line as a root, I'm getting output after the job is executed.

Syed
  • 1
  • 2
  • 1
    possible duplicate of [how do i perform root actions from non-root account?](http://serverfault.com/questions/319737/how-do-i-perform-root-actions-from-non-root-account) – MadHatter Jun 09 '14 at 11:28
  • @MadHatter Tried it but still now working. – Syed Jun 09 '14 at 11:59
  • 1
    Either you mean it's *now working*, in which case, good! Or you mean it's *not working*, in which case I suspect the accuracy of your typing generally. **SHOW us what you've done** - edit the `sudoers` entry into your question, plus the modified line of PHP code that invokes sudo, and the results of `atq` after you've submitted a job. Just **telling us what you think you've done is no help**, because you may well not have done what you think. – MadHatter Jun 09 '14 at 12:08
  • Sorry i meant its not working. I have append more info. – Syed Jun 09 '14 at 13:11
  • @Syed Look at the logfiles. Shortly after the at job has executed, you can type `ls -lart /var/log` to see which file it has logged to. On Ubuntu the logfile to look at is `/var/log/syslog`. – kasperd Jun 09 '14 at 13:59
  • @kasperd Thank you for the suggestion. Where do i find this log on Centos? – Syed Jun 09 '14 at 14:33
  • @Syed type `ls -lart /var/log` to see which logfile was most recently updated. Once the execution time is reached, and the job is removed from the queue, something is going to be logged. – kasperd Jun 09 '14 at 15:27
  • @kasperd I found the solution by granting /bin/sh shell to www user. Im not sure if this is the correct way to fix but for the time being it works. If you have any suggestion feel free to add here, thank you – Syed Jun 09 '14 at 19:06
  • @Syed The script printed by the `atq` command does depend on the `SHELL` variable, so it does make sense, that it would depend on which shell is configured for the user. There might be a way to produce the script with different contents, that do not make use of the `SHELL` variable. That would be cleaner than changing the default shell for the `www` user. – kasperd Jun 09 '14 at 21:02

1 Answers1

0

You seem to have provided output which looks as if it might be a process - but you didn't tell us what this information is nor where you get it from. You state the job is executed hence clearly your php script is able to invoke 'at'. It might not be doing what you expect, bt you have provided no details of what the script is intended to do, nor what resources it requires to acheive that.

The problem is in you script - not it's invocation via 'at'.

symcbean
  • 19,931
  • 1
  • 29
  • 49