Sun 13 Jan 2008
use Net::SSH::Expect;
Enviado al blog por el pinche cash segun el bajo la categoria Perl for Retarded ppl, Scripting, Software
Sin chismes (se el primer chismoso!)
Un nuevo modulo de Expect ha salido, este integra el protocolo SSH al expect-perl, para hacer un poco mas transparente la conexion y concentrar la programacion en las activodades en el shell ya conectado, sin complicarnos la vida en todas las validaciones de la conexion.
El autor del modulo es Bruno Negrao Guimaraes Zica.
#!/usr/bin/perl
use Net::SSH::Expect;#
# You can do SSH authentication with user-password or without it.
## Making an ssh connection with user-password authentication
# 1) construct the object
my $ssh = Net::SSH::Expect->new (
host => "myserver.com",
password=> 'pass87word',
user => 'bnegrao',
raw_pty => 1
);# 2) logon to the SSH server using those credentials.
# test the login output to make sure we had success
my $login_output = $ssh->login();
if ($login_output !~ /Welcome/) {
die "Login has failed. Login output was $login_output";
}# - now you know you're logged in - #
# Starting ssh without password
# 1) run the constructor
my $ssh = Net::SSH::Expect->new (
host => "myserver.com",
user => 'bnegrao',
raw_pty => 1
);
# 2) now start the ssh process
$ssh->run_ssh() or die "SSH process couldn't start: $!";# 3) you should be logged on now. Test if you received the remote prompt:
($ssh->read_all(2) =~ />\s*\z/) or die "where's the remote prompt?"# - now you know you're logged in - #
Incoherencias parecidas y calificaciones a este post:


