python对文件创建时间和大小处理的一个例子
一个zabbix监控脚本
#!/bin/python3 # coding = utf-8 import time import os # 获得最新的报表 dir = "/mnt/elements/GEReports/zip/" file_lists = os.listdir(dir) file_lists.sort(key=lambda x: os.path.getmtime(dir + x)) file = os.path.join(dir, file_lists[-1]) #print(file) # 文件大小 size = os.stat(file).st_size #print(size) # 文件创建时间 file_ctime = os.stat(file).st_ctime print(file_ctime) now = time.time() # 没生成新的报表 if now - file_ctime > 86400: print(1) # 生成了报表但内容为空 if now -file_ctime < 86400 and size < 10000: print(2) # 正常 if now -file_ctime < 86400 and size > 10000: print(0)
努力生活,融于自然