Basically, I have a folder where absolutely huge log files are archived every day. 3 log files are created per day more precisely.
I'm working on a Python script where the user has to enter a date in YYYYMMDD format in order to locate the 3 files that have been created on this date, then he enters a start and end time in hour, minute and seconds and an IP address. And the script will read the content of the 3 .gz files in the given interval and print the lines where the IP address is present.
import re
import os
import glob
import gzip
from datetime import datetime, timedelta
date_entry = raw_input('Enter a date in YEAR, MONTH, DAY format \n')
date = datetime.strptime(re.sub("\s+", "", date_entry), "%Y,%m,%d").date()
path = "/applis/tacacs/log/"
list_of_files = [
file for file in glob.glob(path + '*.gz')
if date == datetime.fromtimestamp(os.path.getmtime(file)).date()
]
debut = raw_input('Start (Hour:Minute:Second) \n')
fin = raw_input('End (Hour:Minute:Second) \n')
Adresse_IP = raw_input('IP Address \n')
filedata = {list_of_files: gzip.open(list_of_files, 'r') for list_of_files in list_of_files}
for line in filedata:
d = line.split(" ",1)[0]
if d >= debut and d <= fin:
re.search(Adresse_IP, line)
print line,
But it doesn't work, when I try the script, nothing happens. There is no error or anything. Even though the IP address I gave should be in the range for at least one of the file I have given. Could someone please provide me with some guidance? I'm still a beginner on Python so maybe my code is completely wrong.