# loop forever
while(1)
{
$TOTAL_TRIES = $TOTAL_TRIES +1;
# loop thru our list of hosts, pinging each
foreach $host (@HOSTS)
{
# get the current time
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
# we assume no response until otherwise proven for this host
$got_response = 0;
# Run the ping command, get results back in stdin
open PING_RESULTS, "/bin/ping -c 1 $host 2>&1 |"
or die "cant fork";
while($line = <PING_RESULTS>)
{
if($line =~ /$PING_RESULT_STRING/)
{
$got_response = 1;
}
}
# OK, we looped through all the data we got back from ping.
# was there anything that indicated we got a response back?
if($got_response == 0)
{
open LOG, ">> $LOG_FILE";
$myTime = time;
printf(LOG "$host $myTime $TOTAL_TRIES $year/$mon/$mday $hour:$min\n");
close LOG;
}
} # end of loop