in reply to Re^2: Net::OpenSSH reconnect master if conn. closed
in thread Net::OpenSSH reconnect master if conn. closed
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:
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.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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Net::OpenSSH reconnect master if conn. closed
by Bolemo (Acolyte) on Sep 28, 2020 at 19:42 UTC |