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

Error - A non-blocking socket operation could not be completed immediately.

by perl514 (Pilgrim)
on Mar 06, 2013 at 13:43 UTC ( #1022010=perlquestion: print w/ replies, xml ) Need Help??
perl514 has asked for the wisdom of the Perl Monks concerning the following question:

Respected Monks,

I am trying a different implementation of a script I had written earlier for checking EMC Celerra NAS Arrays (Uploaded in Cool Uses Of Perl Section). I wanted to check a different command and stuff doesn't seem to work. In order to reduce the error checks to a bare minimum, I wrote a simple script as given below. I have given the loopback IP and a fake username password below but in the script, I am using the correct one. I have also ssh'd into the NAS Array and ran the command from command prompt and that works fine.

#!/usr/bin/perl use warnings; use strict; use Net::SSH2; my $nasip= "127.0.0.1"; my $username = "username"; my $password = "password"; my $ssh2 = Net::SSH2->new(); $ssh2->connect("$nasip") || die "Cant connect to $nasip - $!"; $ssh2->auth_password("$username","$password") || die "Username/Passwor +d not right"; my $chan = $ssh2->channel(); $chan->blocking(0); sleep 10; $chan->exec('nas_server -list') or die "Cannot run the command - $!.$^ +E."; print while (<$chan>);

If I run the script above, I get the following ouptut:

C:\plscripts>perl newmon.pl Cannot run the command - .A non-blocking socket operation could not be + completed immediately. at newmon.pl line 16.

Sorry if my question appears stupid, but is the Net::SSH2 capable of running a command with a space in it? The command I am running in the script this time is nas_server -list and earlier it was /nas/sbin/getreason

.

As can be seen, there's a space between "nas_server" and "-list". I googled up and got to know that the Error I am getting is something to do with a Windows related socket error, but if so, how come I dont get the error when I run the /nas/sbin/getreason command? I have also ssh'd into the NAS Array and ran the command from command prompt and that works fine.Please let me know if I am going wrong somewhere. This script is running on Windows Server 2003 with DWIM Perl 5.14.

Perlpetually Indebted To PerlMonks

use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";
http://dwimperl.com/windows.html is a boon for Windows.

Comment on Error - A non-blocking socket operation could not be completed immediately.
Select or Download Code
Re: Error - A non-blocking socket operation could not be completed immediately.
by BrowserUk (Pope) on Mar 06, 2013 at 14:33 UTC
    A non-blocking socket operation could not be completed immediately.

    The extended error suggests that an attempt to read from the socket has simply failed because there is not yet any data available. A common condition with non-blocking sockets.

    That is -- and this is wild speculation -- the module has probably issued/sent the command to the server; and then entered a read loop in order to retrieve the output; but as the socket is non-blocking, instead of waiting for the output to be available, it is assuming the command has failed rather than retrying.

    Just a guess, but one that fits the scenario.

    Given that your code can do nothing else until it gets the output; why are you setting it non-blocking? Is the module designed to be used that way?

    (Note: I've never used the module and know nothing about its internals or use. But maybe this speculation will help you?)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Hi BrowserUK,

      Thank you for taking time to reply. I was browsing through PerlMonks a few weeks ago while trying to write a similar script that used the Net::SSH2 module and a thread mentioned to set $chan->blocking(0) to get things working. Tried that and it worked. Now, even when I remove it, I still get the same error.

       

      Perlpetually Indebted To PerlMonks

      use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";
      http://dwimperl.com/windows.html is a boon for Windows.

        I don't have anything useful to add I'm afraid. I posted mainly to point out that the extended error is to be expected (and accommodated) with non-blocking handles; and that the logic of your test code shouldn't require non-blocking socket.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Error - A non-blocking socket operation could not be completed immediately.
by zentara (Archbishop) on Mar 06, 2013 at 20:12 UTC
    Just a guess, try shell()?
    #shell use my $chan = $ssh2->channel(); $chan->blocking(0); $chan->shell(); print $chan "ls -la\n"; print "LINE : $_" while <$chan>; print $chan "who\n"; print "LINE : $_" while <$chan>; print $chan "date\n"; print "LINE : $_" while <$chan>; $chan->close;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      Hi Zentara,

       

      Thanks for replying. The shell outputs only the first line. I again tried with the /nas/sbin/getreason command and it gives the output...just when there is a space, I think there is a problem.

      Perlpetually Indebted To PerlMonks

      use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";
      http://dwimperl.com/windows.html is a boon for Windows.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1022010]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-12-29 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls