-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_grep.py
52 lines (47 loc) · 1.81 KB
/
log_grep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys, os, struct, getopt
import logging, time
import re
#grep "DTS" master.log.wf | grep "create task failure" | less
def fileStat(date, fileName):
#query = 'grep "create task" %s | grep %s | grep "DTS" | cut -d " " -f13 |cut -d":" -f2| cut -d"u" -f1 | sort -g | uniq -c'% (fileName, d
ate)
query = 'grep "create task" %s | grep %s | grep "DTS" | cut -d " " -f2 | uniq -c'% (fileName, date)
#query = 'grep "create task failure" %s | grep %s | grep "DTS" | cut -d " " -f2 | uniq -c'% (fileName, date)
print fileName, date, query
pipe = os.popen(query)
for data in pipe.readlines():
print data
pipe.close()
if __name__ == '__main__':
opts, args = getopt.getopt(sys.argv[1:], "m:d:")
for op, value in opts:
if op=="-m":
searchMonth=value
elif op=="-d":
searchDay=value
else:
sys.exit(0)
# searchMonth='07'
# searchDay='28'
searchDate=searchMonth+searchDay
searchStartTimestamp='2013'+searchDate+'000000'
searchStopTimestamp='2013'+searchDate+'235959'
files = os.listdir(os.curdir)
files.sort()
#logFileRegex=r"master.log.wf.\d*$"
logFileRegex=r"master.log.\d*$"
lastInBlock = True
for file in files:
if re.search(logFileRegex, file):
fileDigital = file[11:]
#fileDigital = file[14:]
#print fileDigital, searchStartTimestamp, searchStopTimestamp
if fileDigital < searchStartTimestamp : continue
if fileDigital < searchStopTimestamp:
fileStat(searchMonth+'-'+searchDay, file)
lastInBlock = True
elif fileDigital > searchStopTimestamp and lastInBlock:
fileStat(searchMonth+'-'+searchDay, file)
lastInBlock = False
else:
continue