Also note that I have pm->finish, which is part of Parallel::ForkManager, which allows me to connect to "n" servers at once, and not have to do them in sequence. If you have a lot of servers to check, I'd recommend at least looking into that.my $ssh = Net::SSH::Expect->new ( host => "$serverlist[$host]", user => "$user", raw_pty => 1, restart_timeout_upon_receive => 1, timeout => 6, ssh_option => " -x", ); # Validate that we have a successful ssh connection $login_output = $ssh->run_ssh() or die "Couldn't start ssh pro +cess, error $!\n"; sleep(1); my $ret; my $rc1 = eval{$ret = $ssh->read_all(12);}; unless($rc1) { open(NOCON,">>$NOCONNECT"); print NOCON "$serverlist[$host] - Could not connect -- + skipping.\n"; close(NOCON); $pm->finish(0); # Couldn't connect to this one, skip +to next server in main loop } my $rc = eval{( $ret =~ />\s*|$\s*\z/) or die "where's the rem +ote prompt?";}; if($rc) { if($ret =~ m/[Pp]assword:/) { # print("Server asking for password, key not ins +talled.\n"); open(NOCON,">>$NOCONNECT"); print NOCON "$serverlist[$host] - Asking for p +assword -- skipping.\n"; close(NOCON); $pm->finish(0); # Couldn't connect to this +one, skip to next server in main loop } } $ssh->exec("stty raw -echo"); # Start issuing the commands to check
In reply to Re: Net::SSH::Perl - stops script execution on authentication failure
by sierpinski
in thread Net::SSH::Perl - stops script execution on authentication failure
by GA_L
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |