#!/usr/bin/python # This script mimics the behaviour of tail -f , but has the capablity to execute # a command whenver a line with a matching pattern in it is found. # As you probably see, there's no support for regex or anything of that # flashy nature. # # Erik Ljungstrom 15/10/07 import time import sys import os import socket file = open(sys.argv[2],"r"); node=socket.gethostbyaddr(socket.gethostname())[0] setdef = os.path.getsize(sys.argv[2]) file.seek(setdef-1) while 1: where = file.tell() line = file.readline() if not line: time.sleep(1) file.seek(where) else: pos = line.find(sys.argv[1]) if pos >= 0: os.system("logger -p local6.crit -t postfix amavisd has bailed out on %s!" % (node)) sys.exit(1)