SSH::RPC::Client - The requestor, or client side, of an RPC call over SSH.
version 1.204
use SSH::RPC::Client; my $rpc = SSH::RPC::Client->new($host, $user); my $result = $rpc->run($command, \%args); # returns a SSH::RPC::Result object if ($result->isSuccess) { say $result->getResponse; } else { die $result->getError; }
SSH::RPC::Client allows you to make a remote procedure call over SSH to an SSH::RPC::Shell on the other end. In this way you can execute methods remotely on other servers while also passing and receiving complex data structures. The arguments and return values are serialized into JSON allowing shells to be written in languages other than Perl.
The following methods are available from this class.
Constructs and returns a reference to the Net::OpenSSH object.
Constructor.
The hostname or ip address you want to connect to.
The username you want to connect as.
The password to connect to this account. Can be omitted if you've set up an ssh key to automatically authenticate. See man ssh-keygen for details.
Extended constructor with Net::OpenSSH as parameter.
The hash needs a key with name "host", that is the hostname or ip address you want to connect to. The remaining options in the hash will be used as optinal parameters for a new Net::OpenSSH object.
Blessed reference holding an object that isa Net::OpenSSH, that will be reused for connection.
Execute a command on the remote shell. Returns a reference to an SSH::RPC::Result object.
The method you wish to invoke.
If the method has any arguments pass them in here as a scalar, hash reference, or array reference.
GRID::Machine and IPC::PerlSSH are also good ways of solving this same problem. I chose not to use either for these reasons:
They both allow arbitrary execution of Perl on the remote machine. While that's not all bad, in my circumstance that was a security risk that was unacceptable. Instead, SSH::RPC requires both a client and a shell be written, so you know exactly what's allowed to be executed.
Because SSH::RPC uses JSON as a serialization layer between the connection, clients and shells can be written in languages other than Perl and still interoperate.
The Net::OpenSSH module that SSH::RPC is based upon is fast, flexible, and most importantly way easier to install than the modules required by GRID::Machine and IPC::PerlSSH.
This package requires the following modules:
Net::OpenSSH JSON Class::InsideOut
You cannot use this module inside of mod_perl currently. Not sure why, but it hoses the SSH connection.
JT Smith <jt_at_plainblack_com>
------------------------------------------------------------------- SSH::RPC::Client is Copyright 2008-2009 Plain Black Corporation and is licensed under the same terms as Perl itself. ------------------------------------------------------------------- http://www.plainblack.com info@plainblack.com -------------------------------------------------------------------
To install SSH::RPC::Shell, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SSH::RPC::Shell
CPAN shell
perl -MCPAN -e shell install SSH::RPC::Shell
For more information on module installation, please visit the detailed CPAN module installation guide.