Skip to content

Instantly share code, notes, and snippets.

@chaozh
Created March 29, 2016 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaozh/f81aeccd92ec0d2fb678 to your computer and use it in GitHub Desktop.
Save chaozh/f81aeccd92ec0d2fb678 to your computer and use it in GitHub Desktop.
varnish缓存清理
#!/usr/bin/env python
import sys,os
varnish_adm='varnishadm'
try:
var=sys.argv[1:][0]
if 'http://' in var or 'HTTP://' in var:
domain=var.split('/')[2]
url=var.split(domain)[1]
if url == "":
url=sys.argv[1:][1]
cmd="""%s 'ban req.http.host ~ "%s" && req.url ~ "%s"'"""%(varnish_adm,domain,url)
print "clear:%s url:%s"%(domain,url)
os.system("%s"%cmd)
else:
print "input error!"
except:
print "INPUT ERROR!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment