#!/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 - $@"; }