Check Timezone on multiple servers

#!/bin/bash
# Originally Created by DK - Check remote server Time Zone

#Rewritten completely by Andrew Stringer 23 November 2010 to stop alerts getting sent from servers which are not working.


#turn on debugging, -x starts, +x stops
set +x

SERVERLIST=serverlist.txt
THRESHOLD=0

TMPLOG=/tmp/timechecks.txt-$$
DAY=`date +%b" "%d" "%Y`

#We want UTC for all servers
CORRECTTZ="UTC"

echo "Server TimeZone checks" > ${TMPLOG}
echo "======================" >> ${TMPLOG}
echo ""
echo "From /usr/local/SiteScope/timechecks/check_tz.sh  on mon01" >> ${TMPLOG}
echo "" >> ${TMPLOG};
echo "" >> ${TMPLOG};



for SERVER in `cat ${SERVERLIST}`  ;

do
ZONE=`ssh -q ${SERVER} "cat /etc/sysconfig/clock" | grep  -iE "(ZONE=|TZ=)"`
RESULT=$?
#echo "${RESULT}, ${ZONE}"

#For testing only!
#ZONE='ZONE="GMT"'

if [ ${RESULT} != 0 ]
        then
        echo "Correct response not received from ${SERVER}. " >> ${TMPLOG}
        THRESHOLD=1
        continue
else
        if
                echo ${ZONE} | grep ${CORRECTTZ} > /dev/null
        then
                echo "${SERVER} Ok ( >${ZONE}< )" >> ${TMPLOG}
        else
                echo "TimeZone Not OK on ${SERVER}, is set to >${ZONE}<, should be >ZONE=\"${CORRECTTZ}\"<." >> ${TMPLOG}
                THRESHOLD=1
        fi
fi

done
echo "----------------------------------------------------" >> ${TMPLOG}

#Send mail
if [ ${THRESHOLD} -eq 1 ]
        then
        /bin/mailx -s "RGS Timezone Problems." noc@2ld.com < ${TMPLOG}
fi


rm $TMPLOG
exit 0

rb/checktz.txt · Last modified: 03/10/2014 09:59 by andrew