El Módulo IPC::PerlSSH

Este módulo IPC::PerlSSH permite ejecutar Perl en una máquina remota via una conexión ssh o similar. Vea el siguiente ejemplo:
pp2@nereida:~/src/perl/perlssh$ cat -n prueba.pl
 1  #!/usr/local/bin/perl -w
 2  use strict;
 3  use IPC::PerlSSH;
 4
 5  my $ips = IPC::PerlSSH->new( Host => 'user@orion.pcg.ull.es' );
 6
 7  $ips->eval( "use POSIX qw( uname )" );
 8  my @remote_uname = $ips->eval( "uname()" );
 9  print "@remote_uname\n";
10
11  # We can pass arguments
12  $ips->eval( "open FILE, '> /tmp/foo.txt'; print FILE shift; close FILE;",
13             "Hello, world!" );
14
15  # We can pre-compile stored procedures
16  $ips->store( "slurp_file", <<'EOS'
17    my $filename = shift;
18    my $FILE;
19    local $/ = undef;
20    open $FILE, "< /tmp/foo.txt";
21    $_ = <$FILE>;
22    close $FILE;
23    return $_;
24  EOS
25  );
26
27  my @files = $ips->eval('glob("/tmp/*.txt")');
28  foreach my $file ( @files ) {
29    my $content = $ips->call( "slurp_file", $file );
30    print "$content\n";
31  }
El objeto de conexión es creado en la línea 5. También podríamos crearlo mediante la llamada:
my $ips = IPC::PerlSSH->new( Command => 'ssh user@orion.pcg.ull.es perl' );

o también:

my $ips = IPC::PerlSSH->new( Command => bless ['ssh', 'casiano@orion.pcg.ull.es', 'perl'], 'UNIVERSAL' );

Al ejecutar el programa obtenemos la salida:

pp2@nereida:~/src/perl/perlssh$ prueba.pl
Linux orion 2.6.8-2-686 #1 Tue Aug 16 13:22:48 UTC 2005 i686
Hello, world!
El método eval posibilita la ejecución de código Perl en la máquina remota. El método store permite almacenar una función en la máquina remota. La función puede ser llamada posteriormente mediante el método call.

Casiano Rodríguez León
2010-03-22
"60" ALIGN="BOTTOM" BORDER="0" SRC="lupa.gif" ALT="modulos">perlmonksperldocgoogleetsiiullpcgull
Sig: Práctica: usando cssh Sup: SSH: Secure Shell Ant: Práctica: Producto de Matrices
Casiano Rodríguez León
2010-04-20
:PerlSSH
Casiano Rodríguez León
2010-05-05
ssion] local.host: Requesting channel_open for channel 0. local.host: channel 0: open confirm rwindow 0 rmax 32768 local.host: Got channel open confirmation, requesting shell. local.host: Requesting service shell on channel 0. local.host: channel 1: new [client-session] local.host: Requesting channel_open for channel 1. local.host: Entering interactive session. local.host: Sending command: passwd local.host: Requesting service exec on channel 1. local.host: channel 1: open confirm rwindow 0 rmax 32768 --------- <- MODO INTERACTIVO: old password ********* <- MODO INTERACTIVO: new password ********* <- MODO INTERACTIVO: repeat new password local.host: input_channel_request: rtype exit-status reply 0 local.host: channel 1: rcvd eof local.host: channel 1: output open -> drain local.host: channel 1: rcvd close local.host: channel 1: input open -> closed local.host: channel 1: close_read local.host: channel 1: obuf empty local.host: channel 1: output drain -> closed local.host: channel 1: close_write local.host: channel 1: send close local.host: channel 1: full closed

Casiano Rodríguez León
2011-02-07
jpeg" ALT="perldoc">perlcriticpbpgoogle code project hostingintro a PerlModern Perlblogsgoogleetsiiullpcgull
Sig: El Módulo Net::SSH::Expect Sup: Conexión Automática ssh con Ant: Cifrados
Casiano Rodríguez León
2011-02-21
HTML>