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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.