http://qs321.pair.com?node_id=781929

sqspat has asked for the wisdom of the Perl Monks concerning the following question:

Hello I have a script that uses NET::SSH::Expect to log into a box, issue some commands and then reboot the box and then log back in and issue some more commands, unfortunately when I issue the reboot command the script stops as the ssh connection is lost .... any idea how to get the script not to fall out just because the box has gone down?? I want it just to sleep u ntil box comes back up and can log back in again .... see code below thanks
my $ssh = Net::SSH::Expect->new ( host => "obe140", user => 'root', password => 'admin', raw_pty => 1, timeout => 1 ); #eval { my $login_output = $ssh->login(); if ($login_output !~ /blah/) { die "Login has failed. Login output was $login_output"; } #}; my ($command_file, $commands)= undef; #Open the file with the commands to be issued open(FILE, "input/CMsettings") or die("Unable to open file"); my @commands = <FILE>; close (FILE); $ssh->exec("stty raw -echo"); my $command_run =undef; my @commands_run =(); sleep(1); #insert sleep here so command can be returned. my @issued_commands; #Issue the commands from the comand file foreach my $command1 (@commands){ chomp $command1; $command_run = $ssh->exec($command1); sleep(1); print $command_run; sleep(1); push (@commands_run, $command_run); print "\n\n-----------\n"; } print "\n\n ---- reboot ----\n"; # Issue reboot command my $reboot_command = $ssh->exec('reboot'); -- script drops out here w +hen would like it to hang around until the box is back up and running + so it can issue more commands ????? $ssh->close(); sleep(2); # ---- Login post reboot ----- my $ssh2 = Net::SSH::Expect->new ( host => "obe140", user => 'root', password => 'admin', raw_pty => 1, timeout => 1