[Tutor] get last 7 days string in a log file

Bjørn-Roar Eriksen mediacus at gmail.com
Mon Aug 1 20:13:51 CEST 2011


Hi

I'm new to Python and I'm trying to write a script that's count restart of
an application. The log file contains:
2009-03-06 18:20:26,423  User operation - start nanny
2009-03-06 18:20:26,423  User operation - start all services
And 2009-03-06 18:20:26,423  User operation - start all services tells me
that the application has been restarted.

My script do count it, but I cant figure out how to code so it's only get
from to day and 7 day's back.
#Counts restart of an application
count = 0
with open("c:/test/bre.log")as f:
    for line in f:
        if "User operation - start all services" in line:
            count += 1
            #print line.strip()
    print 'Server restart: %s' % count
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110801/36f07766/attachment.html>


More information about the Tutor mailing list