Jump to content

[SOLVED] bash script fails when called from php within web page


AbeFroman

Recommended Posts

 

I have a bash script that authenticates accounts against Active Directory using the Kerberos "kinit" utility.

 

Script works as expected from command line.  (status return =0) (Linux FC6, Apache 2.2.4,PHP 5.1.6)

When called with the PHP exec command from a web page it fails. (status return =1)

 

Debug commands in the script show it is being called with exactly the same parameters from the command line and from php.

 

I did a chown apache:apache on the script file.

Same results as before.

Status return from the script = 1 when called from PHP and =0 when called from the shell even though params are identical.

I am using the root account.

 

When I run the web page from the command line using "php" it aborts on the statement where I'm checking if the REQUEST_METHOD was a "POST" and nothing else executes after that. Is there an esay way around that?

Tried running it from a generic account. Failed with Status=1.

 

Problem seems to be when script creates a temporary file of "expect" commands.

Looks like it cannot create the file in whatever directory the httpd process is running the script.

 

Fixed that by putting file in the /tmp directory.

 

Now script works when run from command line under generic (non-privileged) account.

 

However , PHP still gets status=1 back when running the script from within web page.

 

 

 

Finally figured it out.

 

On the PHP exec command I added "&>--log-file--"  to capture output from the execution of the shell script.

 

The shell script was unable to find the "kinit" utility in the /usr/kerberos/bin/ directory when executed from within Apache.

 

I simply added the full path to the utility and all is well.

 

Thanks for the suggestions above.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.