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; }

In reply to Net::Telnet issue by vasanth.easyrider

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.