File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424
2525* 基于saltstack的nested输出的运维脚本:
2626 [ * gameops.py* ] ( https://github.com/honglongwei/python-scripts/blob/master/gameops.py )
27+
28+ * 游戏日志监控脚本:
29+ [ * monitor_log.py* ] ( https://github.com/honglongwei/python-scripts/blob/master/monitor_log.py )
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # -*- coding: utf8 -*-
3+
4+ import os
5+ import time
6+ import datetime
7+
8+
9+ def GetLog (num ):
10+ fls = []
11+ for dirpath , dirnames , filenames in os .walk ('/opt/logbak' ):
12+ for filename in filenames :
13+ fn = os .path .join (dirpath , filename )
14+ now_time = datetime .datetime .now ()
15+ last_time = now_time + datetime .timedelta (days = - num )
16+ tg_time = last_time .strftime ('%Y-%m-%d' )
17+ endf = tg_time + '.tgz'
18+ if filename .startswith ('xxx_' ) and filename .endswith (endf ):
19+ if os .path .exists (fn ):
20+ fls .append (fn )
21+ else :
22+ pass
23+ else :
24+ pass
25+
26+ xlog = []
27+ for a in fls :
28+ xlog .append (a [13 :17 ])
29+ xlog .sort ()
30+ return xlog
31+
32+
33+ blog = GetLog (2 )
34+ alog = GetLog (1 )
35+ if len (blog ) > len (alog ):
36+ print '-' + ' ' + ',' .join (list (set (blog ).difference (set (alog )))) #交集:list(set(a).intersection(set(b))) 并集:list(set(a).union(set(b))) 差集:list(set(b).difference(set(a))) # b中有而a中没有的
37+ elif len (blog ) < len (alog ):
38+ print '+' + ' ' + ',' .join (list (set (alog ).difference (set (blog ))))
39+ else :
40+ print 0
41+
42+
You can’t perform that action at this time.
0 commit comments