Check NTP on multiple servers

  #!/bin/bash
  #written Andrew Stringer 23 November 2010 to check ntp lock status.
  #turn on debugging, -x starts, +x stops
  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

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