I thought that the || next; would handle this. However, the script dies after the first attempt:#!/usr/bin/perl use strict; use warnings; use Net::SSH::Perl; my ($ssh, $cmd, $x, $stdout, $stderr, $exit); # commands to be passed to remote server my @commands = ( 'uptime', 'tail /var/log/secure', 'tail /var/log/messages', 'exit'); my $user = 'root'; my $pass = 'root1'; open LOGFILE, "> hw-survey-log" || die "could not open file $!"; # connect to many hosts, on after another for ($x=3; $x<255; $x+=2){ # make new connection $ssh = Net::SSH::Perl->new("10.0.0.$x", protocol => 2) || next; $ssh->login($user, $pass) || next; print LOGFILE "\nHostname: 10.0.0.$x:\n"; # execute all commands foreach $cmd (@commands){ # pass command and record results ($stdout, $stderr, $exit) = ssh->cmd($cmd); print LOGFILE $stdout.$stderr.$exit; } } close LOGFILE;
I can see in the pm code that there is a die:Can't connect to 10.0.0.3, port 22: No route to host at /usr/lib/perl5 +/vendor_perl/5.8.5/Net/SSH/Perl.pm line 206.
It would be nice if there was a way around this without modifying the module.connect($sock, sockaddr_in($rport, $raddr)) or die "Can't connect to $ssh->{host}, port $rport: $!";
Neil Watson
watson-wilson.ca
In reply to Net::SSH::Perl and handling dead hosts by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |