This is my first time working with Net::OpenSSH, and I am attempting to create an SSH for loop, where I print the hostname of the server I am on using whoami. I am ale to SSH to my intended servers from the command line, but when I run my script, I encounter the following error...
ssh: could not resolve hostname
: Name or service not known
username
To get more information, I printed the the output of $ssh->error, where $ssh is my Net::OpenSSH object.
unable to establish master SSH connection: bad password or master process exited unexpectedly at line 24, $fh line 1
This is the script so far...
#!/usr/bin/perl
use strict;
use warnings;
use Net::OpenSSH;
my $file = 'servers.txt';
open (my $fh, $file) or die "Could not open";
while (my $row = <$fh>) {
my $user = "username";
my $password = "password";
my $ssh = Net::OpenSSH->new(host => $row, user => $user, password => $password);
$ssh-error and die "SSH connection failed: " . $ssh->error;
my $whoami = `whoami`;
print $whoami;
}
The servers.txt file is a plain text file with a list of the servers hostnames, one after another.
My understanding is that if I can SSH to these servers from the command line, the problem must lie in the script, and not the servers/network. Any insight into why I Net::OpenSSH cannot resolve a seemingly accessible server would be appreciated.
chompon$row?error).