#!/usr/bin/perl use warnings; use strict; use Net::SSH2; use MIME::Lite; MIME::Lite->send ("smtp", "mail.server.com"); if (!open my $fh , "<" , "C:/path/to/nas_array_ip_list.txt") { my $msg = MIME::Lite->new ( From => 'name@email.com', To => 'name@email.com', Data => "Error:nas_array_ip_list.txt:$!.$^E\n", Subject => "IP List File - nas_array_ip_list.txt - Not Found For $0 Script on $ENV{COMPUTERNAME}\n", ); $msg->send (); } else { print "Please wait. $0 script is being executed...\n"; open my $mailfh, ">", "C:/path/to/dmcheck.txt"; print $mailfh "\n############################################\n"; print $mailfh "\nUser: $ENV{USERNAME} running $0 from $ENV{COMPUTERNAME}\n\n"; print $mailfh "\n###########################################\n"; while (<$fh>) { next if (/^#/); my ($ipname, $ipaddr) = split /\t+|\s+/; my $username = 'username'; my $password = 'password'; my $ssh2 = Net::SSH2->new(); print $mailfh "\n----------------------------"; print $mailfh "\nData Mover Check For $ipname ($ipaddr)\n"; print $mailfh "----------------------------\n"; $ssh2->connect("$ipaddr") || die "PROBELM -$!"; $ssh2->auth_password("$username","$password") || die "Username/Password not right"; my $chan = $ssh2->channel(); $chan->blocking(0); $chan->exec('/nas/sbin/getreason'); sleep 3; while (<$chan>) { chomp; next if (/10 - slot_0 primary control station/); if ($_ =~ /contacted$/) { print $mailfh "DM is OK: $_\n"; } else { print $mailfh "POSSIBLE DM FAILURE:Please check $ipname ($ipaddr): $_ POSSIBLE DM FAILURE:\n"; } }; $chan->close(); } close $mailfh; my $nasmailmsg = MIME::Lite->new( From =>'name@email.com', To => 'name@email.com', Subject => "Automated Check For NAS DataMover Health.", Type => 'Multipart/mixed', ); $nasmailmsg->attach ( Type => 'TEXT', Path => "dmcheck.txt", Filename => "dmcheck.txt", Disposition => 'inline', ); $nasmailmsg->send; system "del dmcheck.txt"; print "$0 execution completed.Please check your mailbox for Mail Titled - \n\"Automated Check For NAS DataMover Health.\"\n"; }