Hello,
I'm trying to write a Perl script for retrieving certain interface statistics from my router ,Cisco 1841.
Authenticating to the device works fine and retrieving output from commands in user-exec mode also works. The problem seems to be that the device prompts for an "enable password" when entering privileged-exec mode.
I'm not experienced with Perl. Any advice on how to get around this would be much appreciated.
I'm trying to write a Perl script for retrieving certain interface statistics from my router ,Cisco 1841.
Code:
#!/usr/bin/perl
use Net::SSH2;
use warnings;
use strict;
my $host = "my hostname";
my $user = "my username";
my $password = "My Password";
my $ssh = Net::SSH2->new();
if(!$ssh->connect($host)){
print("Connection Failed\n");
exit(1);
}
if(!$ssh->auth_password($user,$password)){
print("Authentication Failed");
exit(1);
}
my $channel = $ssh->channel();
my $command = $channel->exec("sh ver") or die $_;
my $output;
my $len = $channel->read($output,2048);
print "output is $output\n";
Authenticating to the device works fine and retrieving output from commands in user-exec mode also works. The problem seems to be that the device prompts for an "enable password" when entering privileged-exec mode.
I'm not experienced with Perl. Any advice on how to get around this would be much appreciated.