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