
![]() |
JasonD
The
Perlmodule that I love called IPC::PerlSSHEssentially it allows you to run PERLon remotemachines via SSH, so do any of you know of a class that will allow me to run CLIPHPon remotemachines via SSH ?http://search.cpan.org/~pevans/IPC- PerlSSH-0.06/lib/IPC/PerlSSH.pmThanks Jason thedarkness
Hey Jason,
Couldn't you just script ssh itself? ssh root@target /path/of/script. phpOr 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 ![]() 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 netresult 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 inApachefor the code. Oh yeah, for got to say that the code for the drones is available via specialapachecalls (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
tnetwould be a very good explanation of how it works![]() 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 PHPmyself and code one, or I could just stick toPerlvia an eval locally to callPHPremotely. Ugly but it'll work I guessperkiset
OK, a little confused.
If you want to code in PHPon a localmachine and talk SSH viaPHPto another box, you need this:http://us2. php.net/manual/en/ref.ssh2.phpIf you want to run PHPcode 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 PHPon a localmachine to talk via SSH to another box and then runPHPcode on it, well, a combo up here would work. Am I just confused?JasonD
quote If you want to code in PHPon a localmachine to talk via SSH to another box and then runPHPcode on it, well, a combo up here would work.You have it right mate. I want to code in PHPonmachine one, that speaks SSH tomachine two, then runs equivalent to....$ perl-e 'print "Hello World "'Once I have that (which is roughly what the above Perlmodule gives) I would then want to wrap it all in a function so it can simply be something likesshserver(foo@bar.com,username,password,'echo "hello world" ![]() Phew..... I hope that makes sense perkiset
Right!
OK, here's essentially how the PHPSSH2 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 phpInfo() page for <that>machine. 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. phpwas chmod as 755 or some such AND you had #! /usr/local/bin/phpat 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! ![]() /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, forPHP?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...
![]() /p JasonD
the -r switch is EXACTLY what I needed to know.
Thank you my friend ![]() 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 machines. A remote worker DB in essence.The reason I want this in PHP, away from my comfort zone ofPerlis a specific piece of code (inPHP ![]() PHPit made me think more about my old way of working and porting it toPHP.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 ![]() perkiset
![]() ![]() ![]() 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 ![]() /p JasonD
lol
![]() Wait till my other toy gets completed. |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads