[user@SERVER10 bin]$ cat checkLog.py
import os
import math
import sys
import datetime
import time
from datetime import timedelta
import shlex, subprocess
import smtplib
import logging
while True:
logging.basicConfig(format='%(asctime)s %(message)s' , \
filename="/opt/strategy/log/restart.log", level=logging.DEBUG)
now = datetime.datetime.now().strftime("%H:%M:%S")
nowFormat = datetime.datetime.now().strftime("%Y%m%d")
cmd = 'tail -n1000 /opt/strategy/log/Server_'+nowFormat+'-*.log | grep -i done | tail -n1 | awk "{print $1}" | cut -d " " -f1| cut -d "." -f1'
callCmd = subprocess.check_output(cmd, stdin=None, stderr=None, shell=True, universal_newlines=False)
strConvert = str(callCmd)
nStr = strConvert[:7]
intConvert = time.strptime(nStr, "%H:%M:%S")
nowConvert = time.strptime(now, "%H:%M:%S")
logTime = time.mktime(intConvert)
nowTime = time.mktime(nowConvert)
timeDiffSeconds = nowTime - logTime
print "======================================================================================================================================================"
print "Difference in Seconds: %d" % timeDiffSeconds
print "======================================================================================================================================================"
print "Log Tuple Date Construct: %s" % intConvert
print "======================================================================================================================================================"
print "Now Tuple Date Construct: %s" % nowConvert
print "======================================================================================================================================================"
print "Log Seconds Conversion: %d" % logTime
print "======================================================================================================================================================"
print "Now Seconds Conversion: %d" % nowTime
print "======================================================================================================================================================"
time.sleep(60)
print "Testing difference in seconds"
if timeDiffSeconds > 600:
print "Done Fitting is no longer working"
os.system("/opt/bin/mailAdmins.sh")
logging.debug('Server has been restarted due to done being over due')
time.sleep(600)