Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: SSH2 - Asynchronous Opens & Synchronous Commands

by 5haun (Beadle)
on Apr 04, 2014 at 13:50 UTC ( #1081143=note: print w/replies, xml ) Need Help??


in reply to Re^3: SSH2 - Asynchronous Opens & Synchronous Commands
in thread SSH2 - Asynchronous Opens & Synchronous Commands

This is an interesting proposal. I'll have to do some tests with this. Thanks. I'll report back with my findings.

Update: I'm still working on this test case. I've got something implemented using Telnet, but I need to do some more testing. I'll post code tomorrow morning.

In the meantime, how would you handle waiting for all the async open requests to complete? I this what wait_for_master is for? My current solution loops checking for $ssh->wait_for_master(1) returning true.

Thanks.

  • Comment on Re^4: SSH2 - Asynchronous Opens & Synchronous Commands

Replies are listed 'Best First'.
Re^5: SSH2 - Asynchronous Opens & Synchronous Commands
by salva (Abbot) on Apr 05, 2014 at 14:14 UTC
    You have to call $ssh->wait_for_master(1) repeatedly until it succeeds:
    my %connecting = map { $_ => 1 } @hosts; while (1) { for my $host (keys %connecting) { my $ssh = $ssh{$host}; if ($ssh->wait_for_master(1)) { delete $connecting{$host}; } elsif ($ssh->error) { # handle connection error delete $connecting{$host}; } } last unless %connecting; select (undef, undef, undef, 0.05); }

      @Salva

      Thank you. So far, it looks like OpenSSH+Telnet will do what we need it to, although I am having to make some adjustments for the use of Telnet.

      BTW, it would be nice (i.e. enhancement request) if $ssh->error provided a message that could differentiate between password, connect, and timeout failures: I get "unable to establish master SSH connection: bad password or master process exited unexpectedly" for authentication, for connect (socket not open), and for timeout errors. I need to be able to differentiate (that was pretty easy to do with Net::SSH2). Unless you have a better test, it looks like I'll need to try a socket connect before the opens to differentiate.

        The connection and authentication phases are carried out by the OpenSSH client and it doesn't pass the cause of the failure back to the module.

        An easy to implement workaround is to redirect the output of the master ssh process to a file and then, to retrieve it when something goes wrong.

        my $ssh = Net::OpenSSH->new($host, master_stderr_file => "/tmp/ssh-std +err-$host", master_opts => ['-v'], ...);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1081143]
help
Chatterbox?
[atcroft]: stevieb: Apparently it was contagious....
[atcroft]: james28909: Make both hands into fists, place them together (with thumbs concealed), and every knuckle is a month (starting with Jan.) has 31 days, every dip (between knuckles) does not....
[atcroft]: (And Feb. is the odd case, because it is 28, unless it is a year divisible by 4, or if it is divisible by both 100 and 400 (at which point it is 29).)
[james28909]: i know but scroll through your calendar on your computer.
[james28909]: i thiught you were going to say make both hands into a fist and puch yourself in the face
[atcroft]: .oO(Sorry, I probably should have said take two normal hands....)
[atcroft]: james28909: No, unless you are a politician, I wouldn't say that (and even if you are, I still probably wouldn't say that).
[james28909]: i mean how hard can it be? its just subtracting days lol
[atcroft]: james28909: What about October 5, 1582?
[stevieb]: atcroft: "Make both hands into fists..."... is something my Ma taught me in our native lang, but I was to ignorant and young to pay attention. Thanks for that :)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2017-04-29 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.