Quoting ThoSi (pe...@th...):
> Hi Folks
>
> I want to use Net:SSH::Perl to automatically run some commands on several
> hosts. All the hostnames are stored in a database.
>
> I decided to use Net::SSH::Perl because I can configure everything I need.
> The auth is done by a SSH-Key (RSA). Unfortunately not all of the hosts in the DB have
> the SSH Key stored in their ~/.ssh/authorized_keys. When I try to connect to one of
> these hosts using SSH2, my script dies because of a Carp::croak() call in the
> Net::SSH::Perl::AuthMgr module (line 142).
>
> Is there a way to turn off this "die" and just get a error-message instead?
> If a hosts doesn't have this ssh-key, I don't want to abort my script, I wnat to continue with
> the next hostname instead.
>
wrap your call in an eval {} construct like so :
eval {
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
}
if ($@) {
warn "Could not connect to $host because of [$@]\n";
}
Hope this helps,
--
Merijn Broeren | She doesn't want you to understand her. She knows that's
Software Geek | impossible. She just wants you to understand yourself,
| everything else is negotiable.
|