Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to ssh connection lost during script running when box rebooted and script falls out... by sqspat

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 making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-28 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found