Jump to content

SSH via script called by system()


AtlasC1

Recommended Posts

Hi everyone,

 

I've searched google and this forum but still haven't really received a straight-cut answer. If this isn't the place to ask this question, please let me know!

 

I've been working on a project that requires an enormous amount of calculation. In a simplified manner... essentially, on the site, a PHP form gathers a few numbers from the user, and the information is stored in a file (input.tmp). Then, I've been using a system("./calc < input.tmp > output.tmp") function to call the program on the server and output its results to output.tmp. Then, the data from output.tmp is plotted using jpgraph back in the user's browser. That has worked fine.

 

However, the calculations take an incredibly long time, so I set up a couple of 2x Quad Core Xeon servers; each one will run its own instance of the calc program to do half the calculations. The calc program is so old, it is extremely difficult to parallelize. So, I wrote a simple script to ssh the two servers. I have keys set up with the apache user/service so no password is necessary. The script and program run without a hitch, when I run them from terminal, but, when the PHP tries to execute the script, all I get is a whole bunch of empty output files. So, the script IS executed by the PHP, but for some reason the ssh doesn't work. Any ideas?:

 

PHP line

system("./start.s");

 

//start.s
box1.s &
box2.s
wait

 

//box1.s
"ssh apache@server1 ./gradif/gradif_mb/calc < files/temp/input1.tmp > files/temp/output1.tmp"

 

//box1.s
"ssh apache@server2 ./gradif/gradif_mb/calc < files/temp/input2.tmp > files/temp/output2.tmp"

 

//Example of an ls -l performed in files/temp:
-rw-r--r-- 1 apache apache 200 May 20 13:59 input1.tmp
-rw-r--r-- 1 apache apache 205 May 20 13:59 input2.tmp
-rw-r--r-- 1 apache apache   0 May 20 13:59 output1.tmp
-rw-r--r-- 1 apache apache   0 May 20 13:59 output2.tmp

 

*note the file sizes of the output files are 0. All machines are running the latest version of Apache, PHP 5+, and RedHat Enterprise Linux version 5.3

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/202435-ssh-via-script-called-by-system/
Share on other sites

Thank you for your quick reply.

 

I've resolved the problem, and figured I would share the solution, in case there are others with the same issue.

 

SElinux was the culprit. I switched it to "disabled" from "enforcing" and it executes flawlessly. Now that I know that SElinux is causing the problem, I can configure things accordingly.

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.