Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Net::SSH2 woes

by syphilis (Canon)
on Jul 02, 2012 at 23:37 UTC ( #979553=note: print w/ replies, xml ) Need Help??


in reply to Net::SSH2 woes

I think the problem is that you're using the same Net::SSH2 object ($ssh) to connect to different hosts, though it's not exactly clear to me that this *ought* to be a problem at all.
Try the below rendition (untested). It creates a new Net::SSH2 object for each host.

use strict; use Net::SSH2; my $hf = 'list.txt'; my $user = 'user'; my $pass = 'pass'; open (L,"<$hf") || die "$!"; while(<L>) { chomp $_; my $ssh = Net::SSH2->new(); $ssh->debug(1); print "Connecting now..\n"; $ssh->connect("$_") || warn "$!"; $ssh->auth_password("$user","$pass"); my $chan = $ssh->channel(); $chan->exec('dir'); $chan->close(); undef $ssh; } close L;
Perhaps the undef $ssh; is unecessary.

Cheers,
Rob


Comment on Re: Net::SSH2 woes
Select or Download Code
Replies are listed 'Best First'.
Re^2: Net::SSH2 woes
by ig (Vicar) on Jul 03, 2012 at 06:32 UTC

    The SSH session is created in Net::SSH2->new(), not $ssh2->connect(). Each SSH session can be used for only one connection, therefore, to connect to a new host, a new SSH session is required. So, you are correct: Net::SSH2->new() must be called for each host, inside the loop.

Re^2: Net::SSH2 woes
by vdubjunkie (Novice) on Jul 03, 2012 at 17:55 UTC
    You had it. I'm actually a bit embarrassed I didn't think of it myself, but I am a bit rusty. I can swear I pulled this format from an example I found some place. Don't people test their examples?! Thanks guys. perlmonks has always been the only place I need for PERL help!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979553]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2015-07-28 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls