Grep kill

Have a tool that you think is awesome enough to be promoted by Hackerthreads? Submit it in a thread here. This forum is write-only, like a drop-box, and you will not be able to see other threads.

Grep kill

Postby Cool_Fire » Fri May 20, 2011 7:11 am

Name of Tool: gkill
Author: Cool_Fire
Language coded in: Bash
What it does: Kill running processes by grep selection

Code: Select all
#!/bin/bash
RESULT=`ps auwwwx | grep $1 | grep -v grep | grep -v $0 | awk '{print $2}'`
 
for PID in $RESULT
do
    kill -9 $PID
done


code with syntax highlighting
If we're breaking the rules, then how come you can't catch us? You can't find us? I know why. Cause, it's ... MAGIC!

Hackerthreads chat, where the party is going 24/7.
User avatar
Cool_Fire
Not a sandwich
 
Posts: 1531
Joined: Fri May 09, 2003 1:20 pm
Location: 41 6d 73 74 65 72 64 61 6d

Re: Grep kill

Postby narada » Fri May 20, 2011 1:57 pm

Quite handy. Thanks for the share. :)
User avatar
narada
Hacker in Training
 
Posts: 92
Joined: Sat Apr 25, 2009 10:05 am

Re: Grep kill

Postby Nautes » Sat Jul 09, 2011 4:13 pm

I made a one-liner code for this one by using egrep and xargs. It will work with either bash or ksh (not sure on csh):

Code: Select all
ps -ef | egrep -vw "ps|grep|$0" | grep -w $1 | awk '{print $2}' | xargs -i{} kill -9 {}


Notice that this (and Cool Fire's version) won't work if you don't have awk installed, maybe using sed will be better for this script.

@Cool Fire: Shouldn't you use a shebang in order to assure the script will be run on bash? (your script also works on ksh).
Nautes
n00b
 
Posts: 1
Joined: Fri Jun 24, 2011 1:57 pm

Re: Grep kill

Postby sanjai » Sat Nov 05, 2011 1:36 am

hi thanks for your information
sanjai
n00b
 
Posts: 1
Joined: Sat Nov 05, 2011 1:35 am

Re: Grep kill

Postby Cool_Fire » Sun Nov 06, 2011 7:45 pm

Nautes wrote:@Cool Fire: Shouldn't you use a shebang in order to assure the script will be run on bash? (your script also works on ksh).


Yes, and I did have one, but I cut it off with some comments that were at the top.
If we're breaking the rules, then how come you can't catch us? You can't find us? I know why. Cause, it's ... MAGIC!

Hackerthreads chat, where the party is going 24/7.
User avatar
Cool_Fire
Not a sandwich
 
Posts: 1531
Joined: Fri May 09, 2003 1:20 pm
Location: 41 6d 73 74 65 72 64 61 6d

Re: Grep kill

Postby Da_Devil » Wed Dec 21, 2011 9:20 am

Cool_Fire wrote:Name of Tool: gkill
Author: Cool_Fire
Language coded in: Bash
What it does: Kill running processes by grep selection

Code: Select all
#!/bin/bash
RESULT=`ps auwwwx | grep $1 | grep -v grep | grep -v $0 | awk '{print $2}'`
 
for PID in $RESULT
do
    kill -9 $PID
done


code with syntax highlighting


I've probably mentionned that in the past but you, Siar, rox.
Da_Devil
Apprentice
 
Posts: 31
Joined: Wed Apr 13, 2011 8:56 am


Return to Tool Submission

Who is online

Users browsing this forum: No registered users and 0 guests