python filter can't output

Posted by Jesse Siu on Stack Overflow See other posts from Stack Overflow or by Jesse Siu
Published on 2012-09-10T09:35:56Z Indexed on 2012/09/10 9:37 UTC
Read the original article Hit count: 190

Filed under:

i create filter by python to the log file like

    Sat Jun  2 03:32:13 2012 [pid 12461] CONNECT: Client "66.249.68.236"
    Sat Jun  2 03:32:13 2012 [pid 12460] [ftp] OK LOGIN: Client "66.249.68.236", anon     password "[email protected]"
    Sat Jun  2 03:32:14 2012 [pid 12462] [ftp] OK DOWNLOAD: Client "66.249.68.236",   "/pub/10.5524/100001_101000/100022/readme.txt", 451 bytes, 1.39Kbyte/sec

the script is

import time
lines=[]
f= open("/opt/CLiMB/Storage1/log/vsftp.log")
line = f.readline()
lines=[line for line in f]
def OnlyRecent(line):
    if  time.strptime(line.split("[")[0].strip(),"%a %b %d %H:%M:%S %Y") < time.time()-(60*60*24*2):
       return True
    return False
print"\n".join(filter(OnlyRecent,lines))
f.close()

but when i run this script, it continue running but didn't show anything until i stop it. Why it can't shows records happened in 2 days.

© Stack Overflow or respective owner

Related posts about python