All pastes #904877 Raw Edit

km

public text v1 · immutable
·published 2008-02-15 10:54 UTC
rendered paste body
my $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";
}