Reputation: 2857
I am writing following script to read list of servers from the text file them ssh to them and run ldd command to fetch the version that is installed on the server. The only problem is the error that I am seeing following error which says Bad Host name:
adev@abclnxdev:[/home/adev/perl-scripts] {63} % perl try.pl
Net::SSH: Bad host name: abclnxtest01
at try.pl line 21
when I manually do the ssh to this host. It gets connect. Here is script :
#!/mu/bin/perl
use Net::SSH::Perl;
use warnings;
my $file = "server-list.txt";
my $usr = "user";
my $pwd = "password";
my $output_file = "GlibC-version.txt";
open(HANDLE, $file) or die("Cant open the file :( ");
@server_list = <HANDLE>;
close(HANDLE);
#debug_print_array(@server_list);
open(HANDLE, ">>$output_file"); #opening file for output.
foreach $host (@server_list)
{
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($usr,$pwd,$ssh);
my($stdout, $stderr, $exit) = $ssh->cmd("ldd --version|grep ldd");
print HANDLE "----------------------------------";
print HANDLE "Hostname : $host";
print HANDLE "GLIBC Version : $stdout";
print HANDLE "----------------------------------\n\n";
}
Upvotes: 0
Views: 538
Reputation: 263177
You have a newline at the end of the server name.
Add:
chomp @server_list;
(And incidentally, it's better to use the newer 3-argument open()
; see http://perlmaven.com/open-files-in-the-old-way .)
Upvotes: 8