-2
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 just take the "user" and the date and time of those lines, but I have no idea how this can be. Someone could give me a light?
Log:
Edith your question and put the code.
– NoobSaibot
Edited and posted the code.
– TMoraes
Shell script meets ide very simple way this. Why not use then?
– Jefferson Quesado