一、程序测试
复制代码 代码如下:# python check_change.py
Usage: python check_change.py update /home/wwwroot
python check_change.py check /home/wwwroot
# python check_change.py update /data/www #生成站点的md5值
# echo ' ' > /data/www/sitemap.html #测试清空文件
# rm -rf /data/www/sitemap.xml #测试删除文件
# python check_change.py check /data/www #查找那些文件被篡改
/data/www/sitemap.xml
/data/www/sitemap.html
二、实现代码如下(check_change.py)
复制代码 代码如下:#!/usr/bin/env python
import os,sys,subprocess
def update(path):
f = open(file,'w')
for root,dirs,files in os.walk(path):
for name in files:
line = os.path.join(root, name)
(stdin,stderr) = subprocess.Popen(['md5sum',line],stdout=subprocess.PIPE).communicate()
f.write(stdin)
f.close()
def check(path):
f = open(file,'r')
for line in f:
check_ok = """echo '%s' | md5sum -c > /dev/null 2>&1""" % line
#print check_ok
if not subprocess.call(check_ok, shell = True) == 0:
abnormal = line.split()
print abnormal[1]
f.close()
def Usage():
print '''
Usage: python %s update /home/wwwroot
python %s check /home/wwwroot
''' % (sys.argv[0],sys.argv[0])
sys.exit()
if len(sys.argv) != 3:
Usage()
file = 'file.key'
model = sys.argv[1]
path = sys.argv[2]
if os.path.exists(path) == False:
print "\033[;31mThe directory or file does not exist\033[0m"
sys.exit()
elif model == 'update':
update(path)
elif model == 'check':
check(path)
else:
Usage()
更新日志
- 孙悦.1996-伙伴【正大国际】【WAV+CUE】
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】