标签:util os.path txt str1 etc new pytho mes bin
统计生成日期为昨天的数据(按日期算,非24小时):#!/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
标签:util os.path txt str1 etc new pytho mes bin
原文地址:http://blog.51cto.com/yangzhiming/2130689