Hi Perl Monks


I have written a perl script to connect to cisco routers and execute command "show interface interface-name". Issue here is that the entire command output is not getting captured. Perl script is -


#!/usr/bin/perl #we will use the minimum required modules or features for our perl scr +ipt use strict; use warnings; use Net::OpenSSH; #Declaring the required variables/arrays my ($DeviceIP, $username, $passwd,$CommandE, $ssh,$expect,$command,$ti +meout,$t); my (@output,@lines); $username = q(newnetcool); $passwd = q(Hello@123); #We will read the input arguments $DeviceIP = q(202.123.37.37); $CommandE = "show interface ae16"; print "Received details are = $DeviceIP and $CommandE\n"; print "The command to be executed is = $CommandE\n"; eval { $ssh = Net::OpenSSH->new($DeviceIP, user => $username, password => + $passwd, timeout => 10, strict_mode => 0); @output = $ssh->capture($CommandE) or die "remote command failed: +" . $ssh->error; print "output start point\n"; print "Device IP = $DeviceIP and Command = $CommandE\n"; print "@output\n"; print "output end point\n"; undef $ssh; }; if($@) { print "Error. Please check - $@"; }

Actual command output is =

---------------------------------


Physical interface: ae16 (MC-AE-16, active), Enabled, Physical link is + Up Interface index: 145, SNMP ifIndex: 5398 Description: #ANG(CEN)-NNI-CEN for BOTH TAG-(ANG-WAO NPE-2(L1:-192.1 +68.53.34),PORT-Te0/0/0/7)-Secondary#Primary##CONNECTED-TO-$BLR-ISP-AC +C-RTR-059$-$xe-2/3/1$##CMR:512754# Link-level type: Flexible-Ethernet, MTU: 9192, Speed: 10Gbps, BPDU E +rror: None, MAC-REWRITE Error: None, Loopback: Disabled, Source filte +ring: Disabled, Flow control: Disabled Pad to minimum frame size: Disabled Minimum links needed: 1, Minimum bandwidth needed: 1bps Device flags : Present Running Interface flags: SNMP-Traps Internal: 0x4000 Current address: 54:e0:32:74:1f:05, Hardware address: 02:23:9c:f4:00 +:ca Last flapped : 2018-06-25 01:24:34 IST (1w1d 13:41 ago) Input rate : 2778310800 bps (669429 pps) Output rate : 7111971424 bps (1013741 pps) Logical interface ae16.101 (Index 7407) (SNMP ifIndex 6805) Description: D-VOIS-ISP-LINK Flags: Up SNMP-Traps 0x4000 VLAN-Tag [ 0x8100.101 ] Encapsulation +: ENET2 Bandwidth: 2000mbps Statistics Packets pps Bytes bps Bundle: Input : 143083 0 9917359 0 Output: 156698 0 10872523 0 Adaptive Statistics: Adaptive Adjusts: 0 Adaptive Scans : 0 Adaptive Updates: 0 Protocol inet, MTU: 9170 Flags: Sendbcast-pkt-to-re Addresses, Flags: Is-Preferred Is-Primary Destination: 125.16.224.192/30, Local: 125.16.224.193, Broadca +st: 125.16.224.195 Protocol multiservice, MTU: Unlimited


But when i capture output through the script the output i am getting is -

----------------------------------------------------------------------------


Physical interface: ae16 (MC-AE-16, active), Enabled, Physical link is + Up Interface index: 145, SNMP ifIndex: 5398 Description: #ANG(CEN)-NNI-CEN for BOTH TAG-(ANG-WAO NPE-2(L1:-192.1 +68.53.34),PORT-Te0/0/0/7)-Secondary#Primary##CONNECTED-TO-$


it is getting captured till $ only. I think the special character is causing the issue. Can you help me how to capture entire output

2018-07-04 Athanasius added code tags


In reply to Special Characters_CommandOutput 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.