walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
# 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); } }
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.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); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Having a difficult time understanding fork()
by crashtest (Curate) on Apr 07, 2010 at 02:19 UTC | |
Re: Having a difficult time understanding fork()
by 7stud (Deacon) on Apr 07, 2010 at 02:55 UTC |