Skip to content

Instantly share code, notes, and snippets.

@rantav
Created January 3, 2013 08:57
Show Gist options
  • Save rantav/4441958 to your computer and use it in GitHub Desktop.
Save rantav/4441958 to your computer and use it in GitHub Desktop.
def kill_by_name(name):
"Kills a process by name (or any unique string). The name is a string from the command line (so be caraful of multiple occurrences)"
cmd = "ps aux | grep '%s' | grep java | grep -v grep | awk '{print $2}' | xargs kill" % name
with settings(hide('stdout'), warn_only=True):
sudo(cmd)
@fascinated
Copy link

In some more modern linux installs, may want to try pkill or pkill -f for a simpler way of accomplishing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment