简体   繁体   English

unix`at`来自php脚本,可在Shell中工作,但不能从Web中工作

[英]unix `at` from php script, works in shell but not from web

I am having trouble executing a unix at job command from a php webscript. at从php web脚本执行作业命令中的unix时遇到麻烦。 the php with the at job looks like this: 带有at工作的php看起来像这样:

$output=exec('echo "/usr/bin/perl /home/dir/test.pl" | /usr/bin/at now +1minute')

This will work fine from the shell command prompt. 这将在shell命令提示符下正常运行。 I can execute the php script, run atq to see that job has been set and the job belongs to root. 我可以执行php脚本,运行atq以查看该作业已设置并且该作业属于root。 Then wait and confirm that the test.pl script has run. 然后等待并确认test.pl脚本已运行。 The test.pl script performs a simple update to a database which I can check to confirm everything has worked. test.pl脚本对数据库执行了一个简单的更新,我可以检查该更新以确认一切正常。

When I execute the php script from the web, go back to my shell and run atq again. 当我从网上执行php脚本时,回到我的shell并再次运行atq I can see that the job has been placed, this time the job belongs to apache, so everything seems fine. 我可以看到工作已经放置,这次工作属于apache,所以一切似乎都很好。 But after waiting for the scheduled time, the test.pl script does not execute which I can confirm after seeing the update to the db has not worked. 但是在等待了预定的时间后,test.pl脚本没有执行,在看到对数据库的更新无效后,我可以确认该脚本。

I belive this must be a permissions issue, but I am not sure. 我相信这一定是权限问题,但是我不确定。 I tried giving /home/dir and the test.pl script ownerships to apache but this still does not work. 我尝试将/ home / dir和test.pl脚本所有权赋予apache,但这仍然行不通。 I tried createing a symlink to /home/dir in the webroot folder but this did not seem to help either. 我尝试在webroot文件夹中创建一个指向/ home / dir的符号链接,但这似乎也无济于事。 I do not know apache permissions to well so I could be overlooking something. 我不知道apache权限是否很好,所以我可能会忽略某些东西。

here is the directory and test.pl ls -l ouput 这是目录和test.pl ls -l ouput

/home/dir
drwxrwxr-x 2 apache apache

test.pl
-rwxr-xr-x 1 apache apache

Thanks for any help on this one. 感谢您对此的任何帮助。

If the job is being enqueued then we can discount the possibility that the apache uid is denied access to 'at'. 如果作业正在排队,那么我们可以排除apache uid被拒绝访问“ at”的可能性。

This then implies that the job is probably failing to execute (how do you know it is failing to run?) 然后,这意味着作业可能无法执行(您怎么知道它无法运行?)

Since you have root access, the next step would be to look at the mail file for the apache uid - or determine where mail for this uid is sent and look there: from the man page : 由于您具有root用户访问权限,因此下一步将是查看apache uid的邮件文件-或确定该uid的邮件发送至何处并在那里查看:从手册页

The user will be mailed standard error and standard output from his commands, if any. 将向用户邮寄标准错误和命令中的标准输出(如果有)。 Mail will be sent using the command /usr/sbin/sendmail 邮件将使用命令/ usr / sbin / sendmail发送

(If you don't find anything there, then you might want to try something like pwd | mail -s test apache or running at with -m to check that mail does get handled as it should) (如果在那里找不到任何东西,那么您可能想尝试使用类似pwd | mail -s test apache或在-m上运行以检查邮件是否得到了应有的处理)

Normally a daemon owner won't have any shell configured - did you set $SHELL before invoking at? 通常,守护程序所有者不会配置任何外壳程序-在调用它之前是否设置了$ SHELL? (if this is the case and the mail is getting sent then there will be a corresponding error waiting to be read). (如果是这种情况,并且正在发送邮件,那么将等待读取相应的错误)。

You've checked the permissions on the test.pl file and that does not appear to be the issue (assuming fACLs or SELinux restrictions are not being applied). 您已经检查了test.pl文件的权限,但这似乎不是问题所在(假设未应用fACL或SELinux限制)。 Have you checked the permissions of the perl executable? 您是否检查了perl可执行文件的权限? Could test.pl be attempting to access other files which it might have permissions on? test.pl是否可以尝试访问可能具有许可权的其他文件?

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

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