Hello, I have a script that works, but I'm trying to add some additional features to it. Right now it will go through the sub check and see if a server is listening for a particular service on two interfaces (it's dual homed). If it is not, then it will run another sub that performs some additional commands. I want to take into account network delay, so if it does notice an interface down initially, I would like for the script to go through the check again before running the run_fix sub. I'm not sure what the best way of doing this without causing an infinite loop. Maybe using redo? I would appreciate any suggestions.
#!/usr/bin/perl -w use strict; use IO::Socket::INET; my @host = ('192.168.149.3', '192.168.15.3'); my $port = '80'; my $connected; check(); sub check { for (@host){ my $sock = IO::Socket::INET->new(PeerAddr => $_, PeerPort => $port, Proto => 'tcp', timeout => '10') and $connected = 1; if ($connected) { print "$_ is listening on port $port.\n"; } else { print "$_ is NOT listening on port $port proceeding to failover.\n" + && run_fix(); } } }
Thank You

In reply to Trying Not To Cause an Infinite Loop 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.