I am having a strange problem and I want to get to the bottom of this:
I have a list of more than 1000 CISCO devices that I need to ssh into and run some commands. So in Perl, I have the following code:
my $scon = Net::SSH::Perl->new("192.168.110.45");
$scon->login($username,$password);
my ($stdout,$stderr,$exit)= $scon->cmd('show run');
print "\n$stdout\n";
And the above code works showing me the output that I need.
But, when I create a loop and try to ssh each device within a loop, I get $stdout as blank.
Below is the code that doesn't work:
my @allhosts = `cat hosts_ip.txt | cut -d',' -f2`;
foreach my $ip (@allhosts) {
my $scon = Net::SSH::Perl->new($ip);
$scon->login($username,$password);
my ($stdout,$stderr,$exit)= $scon->cmd('show run');
print "$stdout\n";
}
The output from above is just blank - It returns nothing.
Any ideas what I am doing wrong?