[Tutor] What am I missing?
Tom Tucker
tktucker at gmail.com
Mon Sep 27 05:58:59 CEST 2004
Good evening! Any thoughts on this one?
The goal is to 'tail -f /var/log/messages' and if the line contains
"CROND" for example, then print that line. The below script does a
great job of tailing and printing, but it prints EVERYTHING.
##################
#!/usr/bin/python
import os, re
findme = re.compile('CROND')
logfile = os.system('tail -f /var/log/messages')
for line in logfile:
found = re.search(findme, line)
if found:
print line,
else:
print "not found"
####################
Thanks,
Tom
More information about the Tutor
mailing list