Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Am I using Net::SSH2 the wrong way?

by salva (Monsignor)
on Jan 18, 2013 at 11:04 UTC ( #1014034=note: print w/ replies, xml ) Need Help??


in reply to Am I using Net::SSH2 the wrong way?

Well, just letting some time elapse in order to ensure that all the data has arrived is not a reliable approach.

Is there any reason for setting the connection in non-blocking mode?

In any case, you can try using Net::SSH::Any instead of Net::SSH2. It can run on top of Net::SSH2 and provides a higher API, making most tasks easier to accomplish. For instance:

use Net::SSH::Any; my $ssh = Net::SSH::Any->new($ipaddr, user => username, password => $p +assword); $ssh->error and die "Unable to connect to $ipaddr: " . $ssh->error; my @lines = $ssh->capture('/nas/sbin/getreason'); for (@lines) { 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"; } }


Comment on Re: Am I using Net::SSH2 the wrong way?
Download Code
Re^2: Am I using Net::SSH2 the wrong way?
by perl514 (Pilgrim) on Jan 18, 2013 at 12:38 UTC

    Hi Salva,

    First of all, thanks for replying with such consistency. You've been replying to all my Net::SSH2 questions.

    As suggested in earlier post, I really dont have the permission to add any extra modules there on my company's Win 2003 Server. It was by pure luck that it happens to have DWIM Perl installed there. But I cannot add any modules there. Cannot even copy files. Hence cannot use the module you suggest

    The module you suggested runs on top of Net::SSH2, so if Net::SSH2 is not able to run the command, then any module that runs on top of that might have same issue.

    Perlpetually Indebted To PerlMonks

    use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";

      Net::SSH2 should be able to run the command. Problem is that getting it do it correctly may be a difficult task that is already solved in Net::SSH::Any.

      You could use its source code (look for the __io3 function) for inspiration, though it is quite convoluted at that level because of all the extra features it supports.

        Hi Salva,

        Unfortunately, there's no way I can put Net::SSH::Any on my company's server. Net::SSH2 is the only go. Any help would be great...

        Perlpetually Indebted To PerlMonks

        use Learning::Perl; use Beginning::Perl::Ovid; print "Awesome Books";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-07-29 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls