Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have added a new restart method for reestablishing the connection to the server in Net::OpenSSH version 0.80. It is something that should have been available a long time ago, but at first it was difficult to implement, then at some point I had to revamp the code managing the master process in order to fix several others bugs making it trivial but didn't though about adding it... until I read your post today!

Note that it is possible that a broken connection goes unnoticed until you actually try to use it. wait_for_master cheeks the local ssh master process but some kind of errors (for instance, a broken TCP connection), would go unnoticed. So to be sure you cover all the cases, you need to try running the command and if that fails, reconnect:

my $cmd = "..."; my $out = $ssh->capture({timeout => 120}, $cmd); unless (defined $out) { warn "unable to run command $cmd, retrying..."; $ssh->restart or die "Unable to restart SSH connection: " . $ssh->er +ror; $out = $ssh->capture({timeout => 120}, $cmd); unless (defined $out) { die "definitively, I can't run the command $cmd: " . $ssh->error; } }
If $cmd does some non-atomic operation, it is a long running operation you don't want to run twice, etc., you may like to use a harmless dummy command as "echo hello" instead.

In reply to Re^3: Net::OpenSSH reconnect master if conn. closed by salva
in thread Net::OpenSSH reconnect master if conn. closed by Bolemo

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found