Usage: checkdns [-u|sage] [-v|erbose] [-d|ebug]
[-s|leep <n>] [-l|ogpath <path>]
-
+
Where:
-u|sage Print this usage
-v|erbose: Verbose mode
- -d|ebug: Emit debug information
-
+ -de|bug: Emit debug information
+
+ -h|ost: Host to check (Default: google.com)
-s|leep <n>: Set sleep period to <n> minutes (Default: 15 minutes)
-l|ogpath <path>: Put the log file in <path> (Default: /var/log)
+ -da|emon: Whether to go into daemon most (Default: yes)
=head1 DESCRIPTION
$0 = $FindBin::Script;
-my $host = 'google.com';
-my $sleep = 15;
-my $initial_sleep = $sleep;
-my $logpath = '/var/log';
-my $log;
+my ($log, $initial_sleep);
+
+my %opts = (
+ host => 'google.com',
+ sleep => 15,
+ logpath => '/var/local/log',
+ usage => sub { Usage },
+ verbose => sub { set_verbose },
+ debug => sub { set_debug },
+ daemon => 1,
+);
sub CheckDNS {
my ($host) = @_;
# Cut down sleep time to monitor this outage more closely but do not go
# below once a minute.
- if ($sleep > 1) {
- $sleep -= $sleep / 2;
+ if ($opts{sleep} > 1) {
+ $opts{sleep} -= $opts{sleep} / 2;
} else {
- $sleep = 1;
+ $opts{sleep} = 1;
} # if
return 1;
} # if
# Successful lookup - set $sleep to $initial_sleep
- $sleep = $initial_sleep;
+ $opts{sleep} = $initial_sleep;
return;
} # CheckDNS
my $msg;
my $errors = $log->errors;
-
- $log->msg ("$errors errors encountered since starting")
- if $errors;
- $log->msg ('Caught interrupt - shutting down');
+ $log->msg("$errors errors encountered since starting") if $errors;
+ $log->msg('Caught interrupt - shutting down');
exit $errors;
} # Interrupt
# Main
GetOptions (
- usage => sub { Usage },
- verbose => sub { set_verbose },
- debug => sub { set_debug },
- 'sleep=i' => \$sleep,
- 'logpath=s' => \$logpath,
+ \%opts,
+ 'usage',
+ 'verbose',
+ 'debug',
+ 'host=s',
+ 'sleep=i',
+ 'logpath=s',
+ 'daemon!',
) or Usage 'Invalid parameter';
+$initial_sleep = $opts{sleep};
+
$SIG {INT} =
$SIG {TERM} = \&Shutdown;
sethostent (0);
$log = Logger->new (
- path => $logpath,
- timestamped => 'yes',
- append => 'yes',
+ path => $opts{logpath},
+ timestamped => 'yes',
+ append => 'yes',
);
$log->msg (
- "Started $FindBin::Script $VERSION logging to $logpath/$FindBin::Script.log"
+ "Started $FindBin::Script $VERSION logging to $opts{logpath}/$FindBin::Script.log"
);
-$log->msg ("Polling DNS on host $host every $sleep minutes");
+if ($opts{sleep} > 1) {
+ $log->msg ("Polling DNS on host $opts{host} every $opts{sleep} minutes");
+} else {
+ $log->msg ("Polling DNS on host $opts{host} every minute");
+} # if
+
+$opts{daemon} = 0 if get_debug;
-EnterDaemonMode
- unless get_debug;
+EnterDaemonMode if $opts{daemon};
while () {
- my $status = CheckDNS $host;
+ my $status = CheckDNS $opts{host};
if ($status) {
- $log->err ("Unable to resolve IP address for $host");
+ $log->err ("Unable to resolve IP address for $opts{host}");
} else {
- $log->msg ("Successfully resolved $host");
+ $log->msg ("Successfully resolved $opts{host}");
} # if
- sleep ($sleep * 60);
+ sleep $opts{sleep} * 60;
} # while
=pod
=begin html
<blockquote>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/Display.pm">Display</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/Logger.pm">Logger</a><br>
-<a href="http://clearscm.com/php/cvs_man.php?file=lib/Utils.pm">Utils</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/Logger.pm">Logger</a><br>
+<a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
</blockquote>
=end html