Jump to content

Running a Korn Script from PHP


Dragoa

Recommended Posts

I'm using PHP 5.2.6, with an Apache2 server running off of a HP-UX 11 box, and I'm trying to call a korn script[pretty sure it's a korn script] from PHP, but it fails and errors out at the line "#!/bin/ksh -n"[so right at the beginning, I'm positive it's this line, since I have this line and this line only in another file and it still returns an error]

 

The error status I get is 138, I have no idea what this means[if anyone has a list of what the PHP exit statuses are I'd be greatly appreciative, I constantly get these exit statuses and I have no idea what they mean and I can't seem to find anything online that has a list of what these things are...]

 

Also: If I remove the "#!/bin/ksh -n" from the script, it runs fine.

 

Any help?

Link to comment
https://forums.phpfreaks.com/topic/110113-running-a-korn-script-from-php/
Share on other sites

I didn't write the script I'm calling, I can't really modify it without going through the process of modifying the rest of the scripts to do the same thing. Besides I have a hunch that whatever this problem is will arise again soon as I do a proper starting of my apache server(#!/usr/bin/perl wasn't working before, but now it magically started working)

I'm using box to mean the machine that runs programs(while you seem to be using server for this). And I'm using server in reference to the Apache Client itself[just clarifying this to make further communication a bit easier].

 

But to respond again. My computer does have KSH installed, and it is located correctly. Permissions look like they're fine for the ksh file. I have not compiled/configured Apache in any special way to actually run KSH specifically.

 

PHP Page[Just the line that calls the code, everything before and after it is just functionality for the page and has no interaction with this line]:

 

echo passthru("/users/dwloader/lee/web/tmp/job_env2", $result);

 

job_env2:

#!/bin/ksh -n
print "Hi";

 

Removing the #!/bin/ksh -n line from job_env2 gives me the proper result[$result = 0 here]. While right now it just fails and returns and $result  = 138.

I'm using box to mean the machine that runs programs(while you seem to be using server for this). And I'm using server in reference to the Apache Client itself[just clarifying this to make further communication a bit easier].

 

Yeah sorry, I refer to the entire machine running services (apache) as a server.

 

With the information you have provided its my opinion that this isn't at all a php issue. PHP is passing execution to your shell just fine, hence your recieving a shell error and not a php one.

 

Can you execute this script from a terminal without issue?

Yes, just tried it and it functions just fine.

 

Although it seems adding the flag -n causes it to do nothing, which is odd considering the script I'm trying to run runs whenever I open up a new x-term window and sets up my environment and it works just fine there. But I tried removing the -n flag and running it from the PHP page again and still nothing, $result is still 138.

Tried exec, turns out that I might be able to straight up remove the #!/bin/ksh line, but I'd prefer not to since whenever I add more functionality it requires a lot of changing.

 

Alright from my user terminal I get: /bin/ksh

 

Using an exec command from a PHP Page I get: /usr/bin/ksh

 

Both of these files exist, both are the same when compared via a comp.

 

Also some testing that was done yesterday: renaming the sh file to ksh, netted a successful running with #!/bin/ksh. So it seems to me that there is something in ksh that is not agreeing with PHP.

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.