It's hard to explain the elation I felt when I found a working ssh module recently. I've hit a low spot though, when I attempted to take my functioning routine and wrap it up inside a list of hosts.
#!/usr/bin/perl
use strict;
use Net::SSH2;
my $hf = 'list.txt';
my $user = 'user';
my $pass = 'pass';
my $ssh = Net::SSH2->new();
$ssh->debug(1);
open (L,"<$hf") || die "$!";
while(<L>) {
chomp $_;
print "Connecting now..\n";
$ssh->connect("$_") || warn "$!";
$ssh->auth_password("$user","$pass");
my $chan = $ssh->channel();
$chan->exec('dir');
$chan->close();
}
close L;
This was a test script I used to simplify troubleshooting, and I still got the following result:
# ./test.pl
Connecting now..
libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type
+, window_size, packet_size, ((void *)0) , 0 ) -> 0x841ed400
Net::SSH2::Channel::DESTROY
Connecting now..
Resource temporarily unavailable at ./test.pl line 14, <L> line 2.
libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type
+, window_size, packet_size, ((void *)0) , 0 ) -> 0x0
Can't call method "exec" on an undefined value at ./test.pl line 21, <
+L> line 2.
Net::SSH2::DESTROY object 0x8663b6c0
It's the "Resource is temporarily unavailable" that I'm seeing when I don't have the debug running. I even threw in a sleep to see if that might help. The first host connects perfectly, and I can run commands, etc. That second host (which by the way IS online) fails reliably. Any suggestions?!