码迷,mamicode.com
首页 > 其他好文 > 详细

统计生成日期为昨天的数据

时间:2018-06-19 18:54:47      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:util   os.path   txt   str1   etc   new   pytho   mes   bin   

统计生成日期为昨天的数据(按日期算,非24小时):

vi a1.py

#!/usr/bin/python

import os
import datetime
import shutil

dir="/ming"

yesterday = datetime.date.today() - datetime.timedelta(days=1)

os.remove("/log/110Hudrm/gmsnew.txt")
os.mknod("/log/110Hudrm/gmsnew.txt")
os.remove("/log/110Hudrm/gmsnew2.txt")
os.mknod("/log/110Hudrm/gmsnew2.txt")

os.chdir(dir)

str1 = "_W"

for root,dirs,files in os.walk(dir):
for f in dirs:
if str1 in f:
ctime = datetime.date.fromtimestamp(os.path.getctime(os.path.join(root,f)))
if ctime == yesterday:
z = open(‘/log/110Hudrm/gmsnew2.txt‘,‘a‘)
z.write(str(ctime)+"\n")
z.close()

                 d = os.path.join(root,f)
                 p = open(‘/log/110Hudrm/gmsnew.txt‘,‘a‘)
                 p.write(d+"\n")
                 p.close()

size = 0
c = open(‘/log/110Hudrm/gmsnew.txt‘,‘r‘)
for i in c.readlines():
for root,dirs,files in os.walk(i.strip()):
size += sum(os.path.getsize(os.path.join(root,fi)) for fi in files)
si = size / 1024 / 1024 / 1024
siz = ("%.1f" % si)
e = open(‘/log/110Hudrm/gmsnew3.txt‘,‘w‘)
e.write(str(siz)+‘G‘)
e.close()

os.system(‘/usr/bin/mail -s "host1(10.0.0.2) ming yesterday new data Size at date +%Y-%m-%d" zhi.yang@ming.com < /log/110Hudrm/gmsnew3.txt‘)

:wq

python a1.py

统计生成日期为昨天的数据

标签:util   os.path   txt   str1   etc   new   pytho   mes   bin   

原文地址:http://blog.51cto.com/yangzhiming/2130689

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!