2

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?

BlueChips23
  • 1,861
  • 5
  • 34
  • 53

1 Answers1

1

Have you seen PSSH? It's a Python script, but it works great for running a few commands quickly on many hosts. It might not be exactly what you're looking for if you're stuck with Perl, but it sounds like this might be a one-time task.

kgraney
  • 1,975
  • 16
  • 20