Last active
August 29, 2015 14:08
-
-
Save YUChoe/80cf6d879ad95f76cfb4 to your computer and use it in GitHub Desktop.
ping with perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Net::Ping; | |
use POSIX; | |
if ($#ARGV == -1) { die "Usage: pinglog {ip address} \n"; } | |
$host = $ARGV[0]; | |
$ping = Net::Ping->new("icmp", 2); | |
$status = "Dead"; | |
while (1) { | |
$old_status = $status; | |
$datestring = strftime "%a %b %e %H:%M:%S %Y", localtime; | |
if ($ping->ping("$host")) { | |
$status = "Alive"; | |
} else { | |
$status = "Dead"; | |
} | |
if ($old_status ne $status) { | |
print "$datestring '$host' is $status\n"; | |
} | |
if ($status == "Alive") { sleep(2); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment