James Oravec
James Oravec

Reputation: 20381

Perl Net::SSH::Any with Key Exchange

I need to be able to use Perl to determine the version of python running on remote servers which I have key exchanges with. To try to accomplish this, I've been using Net::SSH::Any but want to use a key exchange instead of specifying the password in the script. I've looked at cpan's example which specifies the password.

The following is a snippet from my Perl code, which I'm trying to determine if python 2.6 is installed on the remote server.

my $ssh     = Net::SSH::Any->new( $curIP, 'root' );
my @out     = $ssh->capture("python -V");
my $outSize = @out;
my $ver26   = 0;
for ( my $j = 0; $j < $outSize; $j++ ) {
    if ( index( $out[$j], "2.6." ) != -1 ) {
        $ver26 = 1;
    }
}

When I run this, it complains and says a host needs to be specified:

mandatory parameter host missing at ./GenerateConfig.pl line 162

I modified the code to look similar to how this is done in a different post (How can I FTP a file with an SSH key instead of a password, in Perl?) but it also fails:

my $ssh     = Net::SSH::Any->new( $curIP, {'root'} );
my @out     = $ssh->capture("python -V");
my $outSize = @out;
my $ver26   = 0;
for ( my $j = 0; $j < $outSize; $j++ ) {
    if ( index( $out[$j], "2.6." ) != -1 ) {
        $ver26 = 1;
    }
}

How can I do this, or is there an alternative to accomplish the same thing?

Upvotes: 3

Views: 282

Answers (1)

Jim Davis
Jim Davis

Reputation: 5290

According to the documentation for Net::SSH::Any, you need to pass it the hostname and pairs of options:

my $ssh = Net::SSH::Any->new($curIP, user => 'root');

Upvotes: 3

Related Questions