查看oracle固定目录下日志和trace文件大小脚本

python刚入门,在Oracle官网看到个小脚本,感觉挺有意思,经过测试切实可行。

[oracle@ycr python]$ more 5.py 
import datetime
import os
import sys
import time
from pprint import pprint


def readable(size):
  si=('B','KB','MB','GB','TB', 'PB', 'EB', 'ZB', 'YB')
  div = [n for n, m in enumerate(si) if pow(1024, n+1)>size][0]
  return "%.1f%s"%(size/float(pow(1024, div)), si[div])


total = {"log":0, "trace":0}
for path, dirs, files in os.walk(sys.argv[1]):
  for f in files:
    filepath = path+os.sep+f
    if os.stat(filepath).st_mtime>time.time()-(3600*24*int(sys.argv[2])):
      size = readable(os.path.getsize(filepath))
      age = datetime.datetime.fromtimestamp(os.stat(filepath).st_mtime)
      if f in ("log.xml", "alert.log", "listener.log"):
        filetype = "log"
      elif f.endswith("trc") or f.endswith("trm"):
        filetype = "trace"
      else:
        filetype = None
      if filetype:
        total[filetype] += os.path.getsize(filepath)


for a, b in total.items():
  total[a] = readable(b)


pprint(total)


------------------------------------------------------------------------------------
这只是个运维小脚本,参考官网做的测试,希望以后可以自己写一些有用处的。

Clark
2017.07.28

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29135257/viewspace-2122693/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29135257/viewspace-2122693/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值