1 #!/usr/bin/perl -w 2 use Net::SSH::Perl; 3 use strict; 4 my ($stdout, $stderr, $exit) = ('', '', ''); 5 my ($user) = ('yourlogin'); 6 my $pass = 'yourPassword'; 7 my $cmd = 'ls -l'; 8 my $host = 'yourmachine'; 9 my $ssh = Net::SSH::Perl->new($host); 10 $ssh->login($user, $pass); 11 ($stdout, $stderr, $exit) = $ssh->cmd($cmd); 12 print "STDOUT =\n$stdout"; 13 print "STDERR =\n$stderr" if $stderr;El constructor new (línea 9) establece la conexión con
$host
. Entre los parámetros que admite están:
sshd
debe conectarse.
Ejecución:
$ ./example.pl Argument "ssh-dss" isn't numeric in numeric eq (==) at /usr/local/share/perl/5.8.4/Net/SSH/Perl/Key/RSA1.pm line 94, <FH> line 20. STDOUT = total 24 drwxr-xr-x 3 casiano ull 4096 Jul 17 2002 ar drwxr-xr-x 2 casiano ull 4096 May 6 2002 bin drwxr-xr-x 2 casiano ull 52 Dec 17 2001 etc drwxr-xr-x 2 casiano ull 45 Mar 15 2000 include drwxr-xr-x 4 casiano ull 4096 Aug 8 2002 papiguide drwxr-xr-x 4 casiano ull 43 Apr 4 2002 repository lrwxr-xr-x 1 casiano ull 20 Jul 17 2002 scratch -> /scratch_tmp/casiano lrwxr-xr-x 1 casiano ull 26 Jul 17 2002 scratch1 -> /scratch/files/ull/casiano drwxr-xr-x 8 casiano ull 107 Mar 6 2003 src drwxr-xr-x 2 casiano ull 95 Aug 8 2002 tmp lrwxr-xr-x 1 casiano ull 21 Mar 7 2003 unstable -> scratch/unstable/CALL drwxr-xr-x 5 casiano ull 143 Oct 26 2004 work STDERR = MANPATH: Undefined variable.
Casiano Rodríguez León