Hi Perl monks
I have an issue. I have a command to be executed on remote server. I am using Net::Telnet module to connect to remote server. But the command output is not getting captured, not sure why. Can you please help me -
command to be executed - "show isis neighbors"
The code is -
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Switch;
use Net::Telnet();
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n
+"; #reading the hostname, IP address and credentials in a csv file gi
+ven as an argument
my $sum = 0;
my ($host,$hostname,$username, $passwd, $Eleprompt,$t,$string,$match,$
+output,@output);
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
my $i=1;
while(my $line = <$data>)
{
chomp $line;
my @fields = split "," , $line;
$host = $fields[0];
$hostname = $fields[1];
$username = $fields[2];
$passwd = $fields[3];
$Eleprompt = $fields[4];
print "IP of device $i = $host\n";
print "Hostname of device $i = $hostname\n";
print "Username of device $i = $username\n";
print "password of device $i = $passwd\n";
print "login prompt of device $i = $Eleprompt\n";
eval
{
if($t = new Net::Telnet (Timeout => 20, Prompt => $Ele
+prompt))
{
print "Got the expected prompt for $hostname\n
+";
}
print "connection status = $t\n";
$t->open($host);
my $CS = $t->login($username, $passwd);
print "login status = $CS\n";
$string = "show isis neighbors";
$match = $Eleprompt;
@output = $t->cmd("admin show environment leds");
+ #String => $string,Prompt => $match);
print "output is = @output\n";
@output = $t->cmd("show running-config lpts punt exces
+sive-flow-trap"); #String => $string,Prompt => $
+match);
print "output is = @output\n";
@output = $t->cmd(String => $string,Prompt => $matc
+h,Errmode => die); #String => $string,Prompt =>
+$match);
print "output is = @output\n";
};
Sample output of the command -
RP/0/RP0/CPU0:BLR-WFD-MPL-COR-RTR-42-237#show isis neighbors
Fri Feb 23 11:22:50.269 IST
IS-IS IGP neighbors:
System Id Interface SNPA State Holdtime Type IETF-NSF
IS-IS CORE neighbors:
System Id Interface SNPA State Holdtime Type IETF-NSF
BPL-CPT-MPL-COR-RTR-42-241 BE4 *PtoP* Up 27 L2 Capable
BLR-MPL-LTE-PE-RTR-211 BE8 *PtoP* Up 26 L2 Capable
BLR-MPL-LTE-PE-RTR-211 BE70 *PtoP* Up 29 L2 Capable
BLR-MPL-LTE-PE-RTR-211 BE71 *PtoP* Up 22 L2 Capable
BLR-MPL-LTE-PE-RTR-211 BE12 *PtoP* Up 23 L2 Capable
BLR-WFD-MPL-COR-RTR-42-236 BE1 *PtoP* Up 23 L2 Capable
NDL-OKH-MPL-COR-RTR-42-206 BE2 *PtoP* Up 21 L2 Capable
BLL-MPL-LTE-PE-RTR-42-55 BE9 *PtoP* Up 22 L2 Capable
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.