1 #!/bin/sh 2 3 # Monitor NTP drift 4 5 # Copyright (C) 2003-2006 IBM 6 # 7 # This program is free software; you can redistribute it and/or 8 # modify it under the terms of the GNU General Public License as 9 # published by the Free Software Foundation; either version 2 of the 10 # License, or (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, but 13 # WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 # General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20 # 02111-1307, USA. 21 22 if [ -z "$NTP_SERVER" -o "$NTP_SERVER" == "0" ]; then 23 echo "NTP server is not configured." 24 exit 255 25 fi 26 27 # NTP server is set in libpounder.sh 28 # Check NTP server every 15 seconds. Evil, I know. 29 FREQ=15 30 # Threshold at which we warn about excessive drift 31 DWT=100 32 # Threshold at which we fail the test because of drift 33 DFT=500 34 35 LOGFILE=/proc/$$/fd/1 36 37 # Why do we need this? Output is already being logged! 38 cp -f $LOGFILE $POUNDER_TMPDIR/ntpdrift-$$ 39 40 # Do we have a python interpreter? 41 PYTHON=`which python` 42 if [ -n "$PYTHON" -a -x "$PYTHON" ]; then 43 $POUNDER_HOME/timed_loop 900 "$POUNDER_SRCDIR/time_tests/drift-test.py" $NTP_SERVER $FREQ 44 else 45 echo "There is no python interpreter installed. Aborting." 46 exit -1 47 fi 48 49 # Did drift-test.py fail to run properly? 50 if [ $? -ne 0 ]; then 51 exit 1 52 fi 53 54 # Did we see any failures in actual drift test? 55 ERRORS=0 56 cp -f $LOGFILE $POUNDER_TMPDIR/ntpdrift2-$$ 57 diff -u $POUNDER_TMPDIR/ntpdrift-$$ $LOGFILE | while read a b c d e field drift garbage; do 58 if [ "$field" != "drift:" ]; then 59 continue; 60 fi 61 drift=`echo $drift | awk -F "." '{print $1}'` 62 if [ $drift -gt $DFT -o $drift -lt -$DFT ]; then 63 echo ERROR: drift exceeded $DFT ppm: $a $b \ 64 $c $d $e $field $drift $garbage 65 ERRORS=$((ERRORS + 1)) 66 elif [ $drift -gt $DWT -o $drift -lt -$DWT ]; then 67 echo WARNING: drift exceeded $DWT ppm: $a $b \ 68 $c $d $e $field $drift $garbage 69 fi 70 done 71 72 exit $ERRORS 73