#!/usr/bin/perl -w # # NTP time server watchdog script use strict; # Get name of this computer my $host = `hostname`; chomp $host; # Name of file for tracking state my $tmpfile = '/tmp/ntp-watcher-already-complained'; # Make sure ntpd is running my @ps_grep = `ps ax|grep ntpd|grep -v grep`; if (@ps_grep != 1) { print "$host: NTP daemon is not running!\n" unless -e $tmpfile; system "touch $tmpfile"; exit; } # Get status of the server via ntpdc my @status = `ntpdc -c pe`; # Check for PPS peer being locked my $pps_found = 0; foreach (@status) { $pps_found = 1 if /\*PPS/o; } # Error if PPS lock not found if (not $pps_found) { print "$host: PPS synchronization lost!\n" unless -e $tmpfile; system "touch $tmpfile"; exit; } # Clean up state tracking file system "rm $tmpfile" if -e $tmpfile;