JasonD

The

Perl

  module that I love called IPC::

Perl

 SSH

Essentially it allows you to run

PERL

  on remote

mac

 hines via SSH, so do any of you know of a class that will allow me to run CLI

PHP

  on remote

mac

 hines via SSH ?

http://search.cpan.org/~pevans/IPC-

Perl

 SSH-0.06/lib/IPC/

Perl

 SSH.pm

Thanks

Jason

thedarkness

Hey Jason,

Couldn't you just script ssh itself?

ssh root@target /path/of/script.

php

 

Or am I missing something?

Cheers,
td

JasonD

yes but that's not the aim that I want.

For management  reasons it is MUCH simpler to have one control server that contains all the code and then simply contain all the remote servers' (workers) logon details etc and ssh in to run the code remotely without there ever being any actual code permantly stored on those servers.

It is a virtual way to deliver a crappy cluster style system with the only requirement being SSH access.

Personally I love it Applause

perkiset

JD -

I have a similar rig, but went with a pull rather than push setup ie., when it's time to update, the master server pings a little page on the drones, which cause them to "call home" for their instructions. I lock it down so that they only hear a call home instruction from me, and of course, where they call home to is coded and fixed so that someone can't get into the middle of it. In one case, the drones call home under HTTPS because I'm paranoid.

The

net

  result of this is that I can ping lots of drones at once really quickly and update very quickly, or I can do it on a schedule nice and slowly if it is non-critical. Pushing multithreaded is just a bit more cumbersome than simply pinging a bunch then handling HTTP requests in

Apache

  for the code. Oh yeah, for got to say that the code for the drones is available via special

apache

  calls (to drones that are in my DB only) so that the distribution of the code is about as processor friendly as possible.

/p

skyts

Wow that sounds very complicated to do. Reminds me of a "bo

tnet

 ".

JasonD

Yup Bo

tnet

  would be a very good explanation of how it works Applause

I get ya Ed but I really want the push rather than pull thing with nothing more SSH L/P so that the task that is run is solely in memory with never a file on the account permanently stored.

I guess I will have to think a little more about this and may have to delve into

PHP

  myself and code one, or I could just stick to

Perl

  via an eval locally to call

PHP

  remotely. Ugly but it'll work I guess

perkiset

OK, a little confused.

If you want to code in

PHP

  on a local

mac

 hine and talk SSH via

PHP

  to another box, you need this:
http://us2.

php

 

.net

 /manual/en/ref.ssh2.

php

 

If you want to run

PHP

  code on a remote box via SSH then you simply need to put
#! /usr/local/

php

  [the script name]
at the top of the script (above the <?) and then chmod it to 755 and execute it.

If you want to code in

PHP

  on a local

mac

 hine to talk via SSH to another box and then run

PHP

  code on it, well, a combo up here would work. Am I just confused?

JasonD

quote
If you want to code in

PHP

  on a local

mac

 hine to talk via SSH to another box and then run

PHP

  code on it, well, a combo up here would work.


You have it right mate.

I want to code in

PHP

  on

mac

 hine one, that speaks SSH to

mac

 hine two, then runs equivalent to.... 
$

perl

  -e 'print "Hello World "'


Once I have that (which is roughly what the above

Perl

  module gives) I would then want to wrap it all in a function so it can simply be something like

sshserver(foo@bar.com,username,password,'echo "hello world"Applause


Phew..... I hope that makes sense

perkiset

Right!

OK, here's essentially how the

PHP

  SSH2 stuff looks:


<?

php

 
$handle = ssh2_connect('www.mydomain.com', 22);
ssh2_auth_password($handle, 'jasond', 'mypassword');
$stream = ssh2_exec($connection, '/usr/local/bin/

php

  -i');
?>


The return result is a stream as opposed to a simple string. The example above would echo back to you the

php

 Info() page for <that>

mac

 hine. Note that the example does not actually run a script in this case, it simply makes use of an interpreter feature. If you did this:

$stream = ssh2_exec($connection, '/www/sites/my

php

 /ascript.

php

 );

AND ascript.

php

  was chmod as 755 or some such AND you had #! /usr/local/bin/

php

  at the front of it (which interpreter to use ... you know how that works) then the script would execute as you have outlined.

Once all that is done, my recommendation would be to wrap what this stuff into a class rather than functions, so that you could say something like this:


$ssh = new sshHandler();
if (!$ssh->connect($userName, $password)) { die('failed') }

echo $ssh->execute("ps aux");
$ssh ->disconnect();


I think that'd be rather slick actually. In fact, I might just do that myself goddammit! Applause

/p

JasonD

or.......

http://devzone.zend.com/node/view/id/1712

JasonD

Ed. I get you completely but it required files to physically live on the remote server to run.

Is there an equivalent to the -e switch in

Perl

 , for

PHP

  ?

perkiset

It's pretty close... try this:

php

  -r 'echo "hello world ";'

... I think that's what you're looking for

/p

perkiset

Hmmm... now that I look at that and our postings I am considerably more curious about what you're up to my friend...  Applause

/p

JasonD

the -r switch is EXACTLY what I needed to know.

Thank you my friend Applause

As to what I am doing it is like many things in life, can (and probably will be) used for good and evil

On a simple level imagine it as pulling in extra CPU and or RAM resources as requiredfrom within the DB of available

mac

 hines. A remote worker DB in essence.

The reason I want this in

PHP

 , away from my comfort zone of

Perl

  is a specific piece of code (in

PHP

 Applause that has the potential of falling over due to CPU load. As it is written in

PHP

  it made me think more about my old way of working and porting it to

PHP

 .

When this is combined with SSHFS creating a meshed and global FS you have a lovely, centrally managed system for whatever you may want.

My moral. SSH is more MUCH MORE than an encrypted terminal

JasonD

Ahhhh just had an idea.

One piece of code on each of the remote servers is OK.
if the server hasn't been accessed before we can send over a standard script, along the lines of...


#!/usr/bin/

php

  -q
<?
eval $argv[0];
?>


and of course the name of the script, setting it up etc can all be taken place within your class you spoke of before.

So as well as -r this whould work as well Applause

perkiset

Applause Applause Applause

I don't ever want to be on your shit list...

on second thought... hey... why doncha just let me ... um... play with those boxes and that lil itsy bitsy script for a while. I'll just ah... see what it can do  Applause

/p

JasonD

lol Applause

Wait till my other toy gets completed.


Perkiset's Place Home   Politics @ Perkiset's