python删除nginx反响代理缓存代码
时间:2015-06-28 20:49 来源:linux.it.net.cn 作者:IT
#!/usr/bin/env python
'''
Clear nginx a url cache
'''
import os
try:
from hashlib import md5
except:
from md5 import md5
url=raw_input('Please enter url : ')
isClr=raw_input("You sure you want to clear '%s' cache ? (y/n) " % url)
if isClr=='y' or isClr=='Y' :
m=md5()
m.update("%s" % url)
md5url=m.hexdigest()
md5urllen=len(md5url)
dir1=md5url[md5urllen-1:]
dir2=md5url[md5urllen-3:md5urllen-1]
dirPath=("/usr/local/nginx/proxy_cache/%s/%s/%s" % (dir1, dir2, md5url))
isDel=raw_input("Will be deleted : %s (y/n) " % dirPath)
if isDel=='y' or isDel=='Y' :
if(os.path.exists(dirPath)) :
os.remove(dirPath)
print 'delete success'
else :
print 'file not find' (责任编辑:IT)
#!/usr/bin/env python ''' Clear nginx a url cache ''' import os try: from hashlib import md5 except: from md5 import md5 url=raw_input('Please enter url : ') isClr=raw_input("You sure you want to clear '%s' cache ? (y/n) " % url) if isClr=='y' or isClr=='Y' : m=md5() m.update("%s" % url) md5url=m.hexdigest() md5urllen=len(md5url) dir1=md5url[md5urllen-1:] dir2=md5url[md5urllen-3:md5urllen-1] dirPath=("/usr/local/nginx/proxy_cache/%s/%s/%s" % (dir1, dir2, md5url)) isDel=raw_input("Will be deleted : %s (y/n) " % dirPath) if isDel=='y' or isDel=='Y' : if(os.path.exists(dirPath)) : os.remove(dirPath) print 'delete success' else : print 'file not find' (责任编辑:IT) |