Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm using Net::OpenSSH to execute commands on a few remote servers. After the first command completes, I need to reboot the machine and reconnect after it comes back up, then execute more commands. Any advice on an efficient way to reconnect to the rebooted server via SSH as soon as it's back up? i.e. what's a good way to test and see when sshd is once again accepting connections? Here's what I have so far:
my %ssh; my @hosts = qw/ server1.example.com server2.example.com /; my @cmd = "list of shell commands ending with reboot"; for my $host (@hosts) { $ssh{$host} = Net::OpenSSH->new($host, master_opts => [-i => "/path/ +to/ssh_key"], async => 1); $ssh{$host}->error and die "SSH connection to $host failed: " . $ssh +{$host}->error; } for my $host (@hosts) { $ssh{$host}->system("@cmd"); }
This will get me to the point where all of the initial commands are run, and the servers are rebooted. From here, I can't think of a good way to quickly determine when SSHD is running so I can reconnect and continue with the post-reboot commands. I tried variations using $ssh{host}->test("some shell command"); but I'd like to come up with a better solution. Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::OpenSSH fastest way to reconnect to a rebooted machine?
by salva (Canon) on May 17, 2011 at 10:21 UTC | |
by regan99 (Initiate) on May 17, 2011 at 20:07 UTC | |
by salva (Canon) on May 17, 2011 at 20:26 UTC | |
by regan99 (Initiate) on May 17, 2011 at 21:26 UTC | |
by Anonymous Monk on Nov 19, 2012 at 16:49 UTC | |
|
Re: Net::OpenSSH fastest way to reconnect to a rebooted machine?
by thewebsi (Scribe) on May 17, 2011 at 05:31 UTC | |
|
Re: Net::OpenSSH fastest way to reconnect to a rebooted machine?
by patcat88 (Deacon) on May 17, 2011 at 07:01 UTC |