[root@localhost home]# cat remove_maildrop.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Remove files 7 days ago which directory is /var/spool/postfix/maildrop/
#
import os
import datetime
import time
# Get the upper directory of the file that needs to delete
delete_dir = "/var/spool/postfix/maildrop"
# Get local time on last week
date = os.popen("date -d '(date +%Y%m%d) -7 days' +%Y-%m-%d").read().strip()
# Transfort date to structure date
t2 = time.strptime(date, '%Y-%m-%d')
t2 = datetime.datetime(*t2[:3])
# Get list of file name
dir_name = []
# get in directory of delete file
os.chdir(delete_dir)
for filename in os.listdir(os.getcwd()):
file_time = os.popen("stat %s|sed -n '7p'|awk '{print $2}'" %filename).read().strip()
t1 = time.strptime(file_time, '%Y-%m-%d')
t1 = datetime.datetime(*t1[:3])
if t1 > t2:
print "The %s is used in recent week,can`t delete it!" %filename
elif t2 > t1:
print "The %s is changed beyond one week, delete it!" %filename
os.system("rm -rf %s" %filename)
var目录下的maillog保留七天日志
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 此题问题虽小,但是初学者还是很难给出合理的答案的!本文来自老男孩21期网络班学员 面试题:删除一个目录下的所有文件...
- 今天收到nagios报警邮件,其中一台server中的磁盘分区空间超过95%,登录到服务器查看 [root@had...
- 黑色的海岛上悬着一轮又大又圆的明月,毫不嫌弃地把温柔的月色照在这寸草不生的小岛上。一个少年白衣白发,悠闲自如地倚坐...