Tuesday 21 April 2020

SIMPLE PERL SCRIPT TO CONNECT TO ONE OR MULTIPLE NETAPP AND RUN A COMMAND


This is a very simple perl script to connect to netapp and run any command.
Useful for beginners. It can work both in 7mode and cmode.
By the way you can use to to connect to other devices as well :)

#!/usr/bin/perl
use strict;
use warnings;
use lib "/<user directory to keep modules>" # if you don't have internet you can download the modules and keep it here;
use Net::OpenSSH;

use Expect;
$| = 1;

my ($f);
my $username = 'user';
my $password= 'password';
my $cmd = 'version';
my @servers = ('filer1', 'filer2');
foreach $f (@filers) {
 my $ssh = Net::OpenSSH->new("$username\@$f",  timeout => 30, password => $password);
 $ssh->error and die "Unable to connect: " + $ssh->error;
 print "Connected to NetApp Filer :  $f\n";
 my $out = $ssh->capture($cmd) or die "Unable to run command";
   print $out;
}

Guy please like and comment, if you find it useful.

Featured post

Netapp monitoring solution from scratch

I created a netapp monitoring solution on a UNIX machine... and have uploaded the static files to a free php server for so that you under...