Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rb:checkntp [13/03/2012 13:15]
andrew
rb:checkntp [10/10/2013 14:21] (current)
Line 1: Line 1:
 ====== Check NTP on multiple servers ====== ====== Check NTP on multiple servers ======
  
-  ​#​!/​bin/​bash +    ​#​!/​bin/​bash 
-  #written Andrew Stringer 23 November 2010 to check ntp lock status. +    #written Andrew Stringer 23 November 2010 to check ntp lock status. 
-  #turn on debugging, -x starts, +x stops +    #turn on debugging, -x starts, +x stops 
-  set +x+    set +x 
 +     
 +    SERVERLIST=serverlist.txt 
 +    THRESHOLD=0 
 +     
 +    TMPLOG=/​tmp/​ntpchecks.txt-$$ 
 +    DAY=`date +%b" "​%d"​ "%Y` 
 +     
 +     
 +    echo "​Server NTP checks"​ > ${TMPLOG} 
 +    echo "​================="​ >> ${TMPLOG} 
 +    echo ""​ 
 +    echo "From /​usr/​local/​SiteScope/​timechecks/​check_ntp.sh ​ on mon01" >> ${TMPLOG} 
 +    echo ""​ >> ${TMPLOG};​ 
 +    echo ""​ >> ${TMPLOG};​ 
 +     
 +     
 +     
 +    for SERVER in `cat ${SERVERLIST}` ​ ; 
 +     
 +    do 
 +    NTP=`ssh -q ${SERVER} "/​usr/​sbin/​ntpq -p" ` 
 +    RESULT=$? 
 +    #echo "​${RESULT},​ ${SERVER}"​ 
 +     
 +    if [ ${RESULT} != 0 ] 
 +            then 
 +            echo "​Correct response not received from ${SERVER}. " >> ${TMPLOG} 
 +            THRESHOLD=1 
 +            continue 
 +    else 
 +            if 
 +                    echo ${NTP} | grep \* > /dev/null 
 +            then 
 +                    echo "​${SERVER} Ok " >> ${TMPLOG} 
 +            else 
 +                    echo "NTP Not OK on ${SERVER} " >> ${TMPLOG} 
 +                    THRESHOLD=1 
 +            fi 
 +    fi 
 +    
 +    done 
 +    echo "​----------------------------------------------------"​ >> ${TMPLOG} 
 +     
 +    #Send mail 
 +    if [ ${THRESHOLD} -eq 1 ] 
 +            then 
 +            /bin/mailx -s "NTP Problems."​ noc@ww.com < ${TMPLOG} 
 +    fi 
 +     
 +     
 +    rm $TMPLOG 
 +    exit 0
   ​   ​
-  SERVERLIST=serverlist.txt 
-  THRESHOLD=0 
   ​   ​
-  TMPLOG=/​tmp/​ntpchecks.txt-$$ 
-  DAY=`date +%b" "​%d"​ "%Y` 
-  ​ 
-  ​ 
-  echo "​Server NTP checks"​ > ${TMPLOG} 
-  echo "​================="​ >> ${TMPLOG} 
-  echo ""​ 
-  echo "From /​usr/​local/​SiteScope/​timechecks/​check_ntp.sh ​ on mon01" >> ${TMPLOG} 
-  echo ""​ >> ${TMPLOG}; 
-  echo ""​ >> ${TMPLOG}; 
-  ​ 
-  ​ 
-  ​ 
-  for SERVER in `cat ${SERVERLIST}` ​ ; 
-  ​ 
-  do 
-  NTP=`ssh -q ${SERVER} "/​usr/​sbin/​ntpq -p" ` 
-  RESULT=$? 
-  #echo "​${RESULT},​ ${SERVER}"​ 
-  ​ 
-  if [ ${RESULT} != 0 ] 
-          then 
-          echo "​Correct response not received from ${SERVER}. " >> ${TMPLOG} 
-          THRESHOLD=1 
-          continue 
-  else 
-          if 
-                  echo ${NTP} | grep \* > /dev/null 
-          then 
-                  echo "​${SERVER} Ok " >> ${TMPLOG} 
-          else 
-                  echo "NTP Not OK on ${SERVER} " >> ${TMPLOG} 
-                  THRESHOLD=1 
-          fi 
-  fi 
-  
-  done 
-  echo "​----------------------------------------------------"​ >> ${TMPLOG} 
-  ​ 
-  #Send mail 
-  if [ ${THRESHOLD} -eq 1 ] 
-          then 
-          /bin/mailx -s "NTP Problems."​ noc@ww.com < ${TMPLOG} 
-  fi 
-  ​ 
-  ​ 
-  rm $TMPLOG 
-  exit 0 
- 
- 

rb/checkntp.txt · Last modified: 10/10/2013 14:21 (external edit)