perl514 has asked for the wisdom of the Perl Monks concerning the following question:
Respected Monks,
I am almost done with writing a script for running a specific command on our EMC NAS Arrays which return the output of the command E-mail. The script is given at Seeking guidance for more idiomatic way of (re)writing this script.
The problem is, sometimes the script returns empty fields for some nas arrays.The ouptut looks like this:
----------------------------------------------------- Data Mover Check For nasarrayname1 (127.0.0.1) ----------------------------------------------------- DM is OK: 5 - slot_2 contacted DM is OK: 5 - slot_3 contacted DM is OK: 5 - slot_4 contacted DM is OK: 5 - slot_5 contacted ----------------------------------------------------- Data Mover Check For nasarrayname2 (127.0.0.2) ----------------------------------------------------- ----------------------------------------------------- Data Mover Check For nasarrayname3 (127.0.0.3) ----------------------------------------------------- DM is OK: 5 - slot_2 contacted DM is OK: 5 - slot_3 contacted DM is OK: 5 - slot_4 contacted DM is OK: 5 - slot_5 contacted
As shown above, for the array "nasarrayname2" the output is empty. Earlier, this was happening a lot. So I added a sleep command. Now the frequency is reduced but it still happens and it happens for different arrays. When I re run the script manually (currently its running through Windows Scheduler), the nasarray seems to return the output just fine.
----------------------------------------------------- Data Mover Check For nasarrayname1 (127.0.0.1) ----------------------------------------------------- DM is OK: 5 - slot_2 contacted DM is OK: 5 - slot_3 contacted DM is OK: 5 - slot_4 contacted DM is OK: 5 - slot_5 contacted ----------------------------------------------------- Data Mover Check For nasarrayname2 (127.0.0.2) ----------------------------------------------------- DM is OK: 5 - slot_2 contacted DM is OK: 5 - slot_3 contacted DM is OK: 5 - slot_4 contacted DM is OK: 5 - slot_5 contacted ----------------------------------------------------- Data Mover Check For nasarrayname3 (127.0.0.3) ----------------------------------------------------- DM is OK: 5 - slot_2 contacted DM is OK: 5 - slot_3 contacted DM is OK: 5 - slot_4 contacted DM is OK: 5 - slot_5 contacted
Another concern is that the script is supposed to send out a mail if the ouptut does not have certain text, but in this case, it didn't send out any mail.
Given below is some portion of the script:
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"; }
I am not able to understand where I'm going wrong. Should I increase the sleep time? or do I need to run Net::SSH2 output in a different way?
Please help me.
Perlpetually Indebted To PerlMonks
Win 7 at Work. Living through it....Linux at home. Loving it.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Am I using Net::SSH2 the wrong way?
by salva (Canon) on Jan 18, 2013 at 11:04 UTC | |
by perl514 (Pilgrim) on Jan 18, 2013 at 12:38 UTC | |
by salva (Canon) on Jan 18, 2013 at 14:37 UTC | |
by perl514 (Pilgrim) on Jan 18, 2013 at 18:25 UTC | |
Re: Am I using Net::SSH2 the wrong way?
by perl514 (Pilgrim) on Jan 18, 2013 at 12:10 UTC |