my $host = $ARGV[0]; my $online = 0; printLine("pinging $host"); while ($online == 0) { @ping = `ping $host -n 1`; for $line (@ping) { if ($line =~ m/Reply from/) { if ($line =~ m/bytes=/) { printLine("****** $host is up! ******"); $online = 1; printLine("$host is online"); exit 0; } else { $online = 0; } } elsif ($line =~ m/Please check the name and try again/) { print("****** $line ******"); exit 1; } } printLine("$host is down."); } sub printLine { print localtime().": ".shift()."\n"; }