Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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.


In reply to Am I using Net::SSH2 the wrong way? by perl514

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (6)
    As of 2014-11-23 07:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (129 votes), past polls