I'm trying to identify two strings in a log file: "connected" and "disconnected". But I'm not sure how to make it work.
On my server I have stored several log files
import os
import time
import re
data = time.strftime("%d.%m.%Y")
logs = []
#listar os arquivos .LOGS
for file in os.listdir('/var/log/mikrotik'):
if file.endswith(".log"):
if(re.search(data,file)):
logs.append(os.path.join("/var/log/mikrotik", file))
for l in logs:
file=open(l,"r")
for line in file.read():
if re.match("/connected|disconnected/",line):
print line
else:
print line
What I'm trying to do, I check all my .logs that have the current date. and store them in a list, then try to treat each log individually trying to identify the lines that have "connected" and "disconnected", if I find in need only get the "user" and the date and time of those lines, however I do not have idea of how this can be. Could someone give me a light?
Log: