Hi all, Continuing my work after I got good advice to my previous question (thanks quester), I've noticed a weird behavior I don't know how to explain. It doesn't bother me, but I'd like to understand it.

Short description: I am running a script on some HostA and this script resets HostB which I can control via ssh. To resume my interaction s with HostB I wanted to know when is HostB back online again. I followed the advice from quester and in a loop I try to connect to port 22 and read whatever the server listening there is about to say to me. Under normal circumstances, that server is the sshd and I should be reading a line beginning with "SSH". If this does not happen I go to sleep for 3 seconds and try again. I do this until I get my "SSH" line and then I go on with the rest of the script.

The thing is, the reboot procedure does take a while and in my try_to_connect-sleep loop I increment a counter just to see how many times I tried and just get some feedback that my script is still alive and probing the other host. the loop looks like this:

do { $connected = connect(SOCK, $paddr); if($connected) { $line = <SOCK>; print("$line online\n"); close(SOCK); $connected = 0; if ($line =~ /SSH/) {# connected to sshd - I'm ready $done = 1; } else {# connected to ... who the heck is listening on port 22? ...some code here } } else { $attempts++; print("Trying again ... ($attempts) \n"); sleep(3); #sleep 3 seconds before trying again } } while(!$done);
My curiosity was triggered by how the "trying again" messages are printed. First one comes as expected, then then second one comes after 2-4 seconds. The third one can take 10 or more seconds to show up and then they come at 3 sec intervals. I am not bothered by how long it takes to get access to sshd so the fact that the total is around 30-40 seconds is not an issue. I am just curious about this weird timing and why is it always the second iteration?

Any ideas anyone?

Thanks!


In reply to Socket connect curiosity by RaduH

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.