#!/usr/local/bin/python # # Simple Zope monitoring script. # Jason C. Leach. Canada. # import string, os def ScanLines(token, command): #print 'in ScanLines' Status = 0 # fetch data Lines = PipeInput(command) # cycle through the input for line in Lines: # if a line contains the 'daemons' name, just exit gracefully. Status = string.find(line, token) #print Status #print line # should exit if Status >= 0: Status = 1 break else: Status = 0 #print 'done ScanLines' return Status def PipeInput(command): # check to make sure the disks are not to full. #print 'int PipeInput' # variable decleration Lines = [] # open pipe to os command pipe = os.popen(command, 'r') # fetch input Lines = pipe.readlines() # close the pipe pipe.close() return Lines def GetPid(FILE): fin = open(FILE, 'r') pid = fin.readline() fin.close() return pid if __name__ == '__main__': TOKEN = 'Zope' ZOPEPID = '/usr/local/www/Zope/var/zProcessManager.pid' CMD = 'ps -p ' + GetPid(ZOPEPID) + ' | grep Zope' SCRIPT = ' /usr/local/etc/rc.d/zope.sh start' Status = ScanLines(TOKEN, CMD) if not Status: os.system(SCRIPT) #return 1