#!/usr/bin/perl
#we will use the minimum required modules or features for our perl script
use strict;
use warnings;
use Net::OpenSSH;
#Declaring the required variables/arrays
my ($DeviceIP, $username, $passwd,$CommandE, $ssh,$expect,$command,$timeout,$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 - $@";
}
####
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.168.53.34),PORT-Te0/0/0/7)-Secondary#Primary##CONNECTED-TO-$BLR-ISP-ACC-RTR-059$-$xe-2/3/1$##CMR:512754#
Link-level type: Flexible-Ethernet, MTU: 9192, Speed: 10Gbps, BPDU Error: None, MAC-REWRITE Error: None, Loopback: Disabled, Source filtering: 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, Broadcast: 125.16.224.195
Protocol multiservice, MTU: Unlimited
####
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.168.53.34),PORT-Te0/0/0/7)-Secondary#Primary##CONNECTED-TO-$