#!/usr/bin/python __author__ = "Gabriel Ignacio Dain" __doc__ = """ Gkill takes input from unix pipes and autamically kills the listed processes. This comes in handy when having to kill many similar processes, or as a shortcut for lazy sysadmins. The syntax is described by the help() function. Gabriel Ignacio Dain (gabrieldain@gmail.com). GPLv2 2007""" import re import sys import os def args(input, args=["/bin/kill"]): """Cleans the input and returns a list of PIDs to kill. Having "/bin/kill" as the first argument is necessary for kill to execute correctly.""" for string in input: if len(string) > 1: args.append(string.split()[0]) else: pass return args def help(): """Displays author, contact and usage information.""" print """ Gkill by Gabriel Ignacio Dain (gabrieldain@gmail.com). GPLv2 2007 Gkill takes input from unix pipes and autamically kills the listed processes. This comes in handy when having to kill many similar processes. Gkill expects to recieve a list of processes from the standard input. This list can be easily created by piping the output of ps into Gkill; ps [-a|-A] | gkill However, this would kill all current processes. Using grep is the easiest solution; ps [-a|-A] | grep APPLICATION | gkill Note that this syntax is also valid: echo PID | gkill While less useful for normal intercation with the shell, this might prove useful for scripting purposes [ running gkill with any arguments will show this message ]""" if len(sys.argv) > 1: help() else: os.execv('/bin/kill', args(sys.stdin.read().split("\n")))