vasanth.easyrider has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Special Characters_CommandOutput
by Lotus1 (Vicar) on Jul 03, 2018 at 13:36 UTC | |
|
Re: Special Characters_CommandOutput
by salva (Canon) on Jul 03, 2018 at 16:56 UTC |