暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
Oracle alert日志检查脚本
1388
2页
17次
2019-11-14
10墨值下载
Oracle alert 日志检查脚本
个人使用的一个使用python开发的检查Oracle alert日志的脚本,逻辑是检查上次检查以来新产生的
内容行是否有特定的错误,同时会标记错误发生的具体时间,提供给有需要的朋友。
#!/usr/bin/env python
#coding=utf8
import io
import datetime
import time
import traceback
import linecache
import sys
import time
import os
def checkalerterrror(alertfilename):
 daylist=['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
 keywordlist=['ORA-','Error','Starting ORACLE instance','Shutting down
instance','.trc','fail','WARNING','Warning']
 alertlogfileconfig =
os.getcwd()+os.path.sep+'config.'+alertfilename.split('/')[-1]+'.ini'
 eventdate=datetime.datetime(1, 1, 1, 0, 0)
 startline = 0
 try:
   with open(alertlogfileconfig,'r') as f:
startline = int(f.read())
 except:
print(traceback.format_exc())
 try:
'''
count = -1
for count,line in enumerate(open(alertfilename,'rU')):
     pass
count += 1
'''
countnums = os.popen('wc -l ' + alertfilename).readline()
count = int(countnums.split()[0])
with open(alertlogfileconfig,'w') as f:
     f.write(str(count))
   if startline > count :
     print('Attention ,the startline is ' + str(startline) +' , the
endline is ' + str(count) + ' ,so reset the startline to 0')
     startline = 0
     print()
   lines = linecache.getlines(alertfilename)[startline:count]
   for line in lines :
     if len(line) > 3 and line[0:3] in daylist:
       eventdate = datetime.datetime.strptime(line.rstrip('\n'), '%a %b
%d %H:%M:%S %Y')
     elif len(line) > 3 :
       for w in keywordlist:
         if w in line:
           print(eventdate)
   print(line)
 except:
   print(traceback.format_exc())
if __name__ == '__main__':
 #alertfilename = r'/u01/app/oracle/diag/rdbms/ads/ads/trace/alert_ads.log'
 alertfilenames =
[r'/u01/app/oracle/diag/rdbms/ads1/ads1/trace/alert_ads1.log',
r'/u01/app/oracle/diag/rdbms/ads/ads/trace/alert_ads.log',r'/u01/app/oracle/diag
/rdbms/ads2/adsa/trace/alert_adsa.log']
 for alertfilename in alertfilenames:
   checkalerterrror(alertfilename)
of 2
10墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜