#!/bin/bash
#
# script to check whether the time of the computer is off
# offset is inserted into the database
# 

offset=`/usr/sbin/ntpdate -d ptbtime1.ptb.de 2>/dev/null | grep '^offset*' | cut -d' ' -f2`
query="INSERT NTPDate set fOffset="$offset", fMachineKEY=(SELECT fMachineKEY from Machine WHERE fMachineName='"$HOSTNAME"'), fTime=Now()"
# host needs full address to work also on fact01
/usr/bin/mysql -u systemstatus --host=fact01.fact.local SystemStatus -e "$query"

if [ $offset -gt 1 ] || [ $offset -lt -1 ]
then
   echo `date`": time difference of "$offset" sec on "$HOSTNAME
fi

