Basically, what I am trying to do is this: I have a timer that does a countdown from a specified time. I would like for that timer to do a countdown, while in the background a command is being run. As soon as the command gets the output that it needs, the timer is ended and the script resumes flow. Here's what I have:

# Countdown Timer sub sleep_count { my $minutes = shift; my $string = shift; my $command = shift; my $command_time_interval = shift; my $countdown = $minutes*60; # in secs. $| = 1; my $beg_time = time; my $end_time = $beg_time + $countdown; for (;;) { my $time = time; last if ($time >= $end_time); printf("\r[ %02d:%02d ] $string", ($end_time - $time) / ( 60) % 60, ($end_time - $time) % 60, ); sleep(1); } }
my $pid = fork(); if ($pid == 0) { sleep_count(3, 'Verifying with Nagios that resin is down: '); } else { my $nagios_check = `/usr/lib/nagios/plugins/check_http -H host.com + -I $ip -p 80`; until ( $nagios_check !~ /HTTP OK HTTP\/1.0 200 OK/ ) { $nagios_check = `/usr/lib/nagios/plugins/check_http -H host.co +m -I $ip -p 80`; sleep 10; } waitpid($pid,0); }
So basically what I am trying to do is check Nagios every 10 seconds for 3 minutes until the server is reported as down. While this check is going on there is a timer that reports how much time of the 3 minutes is left. As soon as Nagios returns that the server is down, the timer is stopped and script continues on.

I realize I am probably not on the right track, but any help is really appreciated. Thanks guys/girls!

In reply to Having a difficult time understanding fork() by walkingthecow

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.