Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   ssh using php (http://www.go4expert.com/forums/ssh-using-php-t13707/)

ub007 11Sep2008 01:43

ssh using php
I have setup an intranet of 10 machines(all running Ubuntu).One of them is the server hosting lets say Example Web Page. I use the other 9 machines to load test the server.Also intend to set up one PC as the master.So I have a master with 8 slaves testing www.example.com.The test scripts are installed on all the 9 machines & I have a browser form interface on my master node....

The form looks like


SERVER(enter in the format 'www.example.com'): <input type="text"
name="server" /><br />
AGENT: <input type="text" name="threads" /><br />
INTERVAL: <input type="text" name="interval" /><br />
RAMPUP: <input type="text" name="rampup" /><br />
No of Client MAchines: <input type="text" name="machines" /><br />
testvector: <input type="text" name="test" /><br />
<input type="submit" value="GO" />
The GO button calls another php script which ssh s into the slave nodes and run the test scripts

So i could do a test like ->
load server(Example Web Page) using 3 client machines; stressing vector 'webserver' (//one of the many testing programs installed on the client machines)

A sample php code would look (this is only for 3 machines)


$machineValues = array("", "root", "password","david", "", "root", "password2","david2", "", "root2",
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't
// log in at server1.example.com on port 22

for ( $counter = 0; $counter < sizeof($machineValues); $counter =
$counter+4) {

if(!($con = ssh2_connect($machineValues[$counter], 22))){
echo "fail: unable to establish connection\n";
echo "Machine number $counter is $machineValues[$counter]";
} else {
// try to authenticate with username root, password secretpassword
    if(!ssh2_auth_password($con, $machineValues[$counter+1],
$machineValues[$counter+2])) {
      echo "fail: unable to authenticate\n";
    } else {
    // allright, we're in!
      echo "okay: logged in...\n";
      // execute a command
      $stream = ssh2_exec($con, 'python/home/'.$machineValues[$counter+3].'/Desktop/hello.py');
      stream_set_blocking($stream, true);
      while($line = fgets($stream)) {
      echo $line."<br />";


Now,lets say I select from the form

No of Client MAchines : 1

The code ssh into and runs the script.

However i still got 'ip' => "" and 'ip' => "" available and I may wish to use that after a certain time delay...

So i wish i could create some code that would enable the browser interface to give a message something like
"you got 2 more machines available!" Would you like to add more?:thumbs:

I would add one more field in the form
More Client MAchines: <input type="text" name="machines" /><br />

Eg.User selects 1, when they click submit,the PHP code should ssh into the next machine available which is ""....and then report back,"you got 1 more machine available!" and so on.......

How would i do that?

asha 17Oct2008 10:40

Re: ssh using php
I don't know how much possible it is with PHP, but in Perl there are lot of modules at http://cpan.org to help you out.

All times are GMT +5.5. The time now is 05:50.