Skip to content

Instantly share code, notes, and snippets.

@harlo
Last active August 29, 2015 14:05
Show Gist options
  • Save harlo/def27e720cb88c346757 to your computer and use it in GitHub Desktop.
Save harlo/def27e720cb88c346757 to your computer and use it in GitHub Desktop.
force quits some of my packages
import re
from sys import argv, exit
from fabric.api import settings, local
if __name__ == '__main__':
try:
target = argv[1]
except Exception as e:
print e
print "usage: skillet.py [module name (i.e. compass_frontend)]"
exit(1)
if target not in ['compass_frontend', 'informa_frontend', 'unveillance_annex']:
print "usage: skillet.py [module name (i.e. compass_frontend)]"
exit(1)
with settings(warn_only=True):
whoami = local("whoami", capture=True)
kill_list = local("ps -ef | grep %s.py" % target, capture=True)
for k in kill_list.splitlines():
if re.match(".*\d{2}:\d{2}:\d{2}\s/bin/sh", k) is not None: continue
if re.match(".*\d{2}:\d{2}:\d{2}\sgrep", k) is not None: continue
pid = re.findall(re.compile("\d{4}|%s\s+(\d{3,6})\s+.*" % whoami), k)
if len(pid) == 1:
try:
pid = int(pid[0])
except Exception as e:
print "ERROR: %s" % e
continue
with settings(warn_only=True): local("kill -9 %d" % pid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment