vasanth.easyrider has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl monks
I have a requirement. Need to do telnet to a remote router and execute 2 commands and capture the output. I have written perl code, given below. The issue i am facing is, output is getting captured for first command, but for second command, output is not getting captured. I am providing sample outputs for both the commands (may be it will help is identifying the reason for this issue)
Note - Is this issue because of empty lines in the command 2 output? please suggest
command 1 sample output -
Fri Feb 23 15:10:52.014 IST
R/S/I Modules LED Status
0/RP0/*
host Critical-Alarm Off
host Major-Alarm Off
host Minor-Alarm Off
command 2 sample output -
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
Perl code -
#!/usr/bin/perl use strict; use warnings; use Switch; use Net::Telnet(); my ($host,$hostname,$username, $passwd, $Eleprompt,$t,@output); $host = q(10.0.0.225); $username = q(user_name); $passwd = q(My_Password); $Eleprompt = q(RP\/0\/RSP0\/CPU0:LCK-MPL-PE-RTR-225\#); eval { if($t = new Net::Telnet (Timeout => 20, Prompt => $Eleprompt)) { 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"; @commandoutput1 = $t->cmd("admin show environment leds"); print "output is = @commandoutput1 \n"; @commandoutput2 = $t->cmd("show isis neighbors"); print "output is = @commandoutput2 \n"; }; if($@) { print "since we got error w.r.t shell prompt for the IP $host, +we are proceeding with next device\n - $@"; next; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::Telnet issue
by poj (Abbot) on Feb 23, 2018 at 12:38 UTC | |
by Anonymous Monk on Feb 23, 2018 at 15:42 UTC | |
by Corion (Patriarch) on Feb 23, 2018 at 15:49 UTC | |
by Anonymous Monk on Feb 23, 2018 at 15:58 UTC | |
by poj (Abbot) on Feb 23, 2018 at 16:47 UTC | |
| |
|
Re: Net::Telnet issue
by thanos1983 (Parson) on Feb 23, 2018 at 12:39 UTC |