#!/usr/local/bin/perl -w use strict; use Net::Ping; use MIME::Lite; unless(@ARGV) { print "Supply a file with hostnames \(example usage\)-- \n$0 /etc/hosts\n"; exit; } my @host_array=<>; my $p = Net::Ping->new("icmp"); foreach our $host (@host_array) { print "$host is "; &tryagain ($host) unless $p->ping($host, 5); print "reachable.\n"; } $p->close(); sub tryagain { print "NOT "; sleep (60); my ($host)=@_; my $p = Net::Ping->new("icmp"); foreach our $host (@_) { ¬ify ($host) unless $p->ping($host, 30); } $p->close(); } sub notify { my $date= localtime(time); my ($host)=@_; my $msg=MIME::Lite-> new( From =>'ICMP Monitor ', To =>'linebacker@perlmonks.org', Subject =>'Ping Failure', Data =>"Ping failure for $host at $date" ); $msg->send; }