How to do this without polling, and with an unmodified target machine?

This might be very complicated to do Perl (there is hope, Net::Pcap exists), but listen on the ethernet port (sniffing, pcap, etc) for the broadcasted DHCP packet that the rebooting machine will put out on the ethernet wire. What about SNMP against the DHCP server?

If you can modify the target machine, have the target machine do a wget on boot on a dynamic dns address, that happens to be your machine, you can run a small perl webserver based off HTTP::Daemon on your side, the server on boot connects to your perl mini-server and the perl script on your side wakes up and continues with the rest of the SSH commands. Remember to consider timeouts and retrys by wget, you can deadlock if wget can't wake up your Perl SSH script for some reason. The keywords "watchdog" or "heartbeat" are relevant. Also remember if you make a miniserver off HTTP::Daemon, what happens if 2 servers try to connect to the miniserver at once (assuming you dont serialize the SSH command execution and rebooting, you probably do)? In my experience, the OS just queues the 2nd attempt, if you dont call another accept() fast enough, the remote side will time out.

On some networks you might get an ICMP unavailable packet if the ethernet port of the server is down, rather than a plain old timeout. Might wanna somehow separate in code a plain timeout from an ICMP unavailable.

In reply to Re: Net::OpenSSH fastest way to reconnect to a rebooted machine? by patcat88
in thread Net::OpenSSH fastest way to reconnect to a rebooted machine? by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.