Automation of "Kill script by name"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automation of "Kill script by name"
# 1  
Old 07-11-2012
Automation of "Kill script by name"

The following "NAME" is the keyword to use to kill all processes containing it. While the command is very useful, it is user-unfriendly to type it in terminal. I've tried alias and make it a shell script but as NAME is inside awk so the problem becomes complicated. Could anybody advise?

Code:
ps -ef | awk '/NAME/{print $2}' | xargs kill


Last edited by Scrutinizer; 07-11-2012 at 06:19 AM.. Reason: code tags
# 2  
Old 07-11-2012
You can user variable instead of alias.....
# 3  
Old 07-11-2012
User variable works for pattern but not awk

Usage of pattern is good but awk still doesn't know what $2 means now. What should $2 be replaced in a shell script then?
Code:
pattern=$1                                                                                                                                                                        
#ps -ef | awk '/$pattern/{print $2}' | xargs kill                                                                                                                                 
echo "ps -ef | awk '/$pattern/{print $2}' | xargs kill"

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 07-11-2012 at 08:34 AM..
# 4  
Old 07-11-2012
Bug try this.....

Code:
 
var="jumper_2.sh"
$ ps -ef | awk -v VD=$var '/VD/{print $2 }'
6361
$ echo "kill -9 `ps -ef | awk -v VD=$var '/VD/{print $2 }'`"
kill -9 6361

# 5  
Old 07-11-2012
Please don't suggest kill -9 usage.

-9 switch should only be used in extreme situations....
# 6  
Old 07-12-2012
Quote:
Originally Posted by pamu
Code:
 
var="jumper_2.sh"
$ ps -ef | awk -v VD=$var '/VD/{print $2 }'
6361
$ echo "kill -9 `ps -ef | awk -v VD=$var '/VD/{print $2 }'`"
kill -9 6361

Thank you for providing the complete code but I don't quite get how it differs from mine. In my previous code, I made "var" as the pattern to match. Now it seems that you make it a shell script? And then I don't know whether you type in 6361 or it is written in the script. Sorry that I cannot test the code because kill is too damaging and I can't risk killing other users' processes.
# 7  
Old 07-12-2012
Quote:
Originally Posted by watashi
The following "NAME" is the keyword to use to kill all processes containing it. While the command is very useful, it is user-unfriendly to type it in terminal. I've tried alias and make it a shell script but as NAME is inside awk so the problem becomes complicated. Could anybody advise?

Code:
ps -ef | awk '/NAME/{print $2}' | xargs kill

Just use:
Code:
pkill -f NAME

To identify the processes that would be killed:
Code:
pgrep -f NAME

This User Gave Thanks to jlliagre For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

What is the use of "finger" command & how to use it to kill the online processes ?

Hi there, I am eager to know what exactly is the use of "finger" command & how to use it to kill the online processes ? :b: (1 Reply)
Discussion started by: abhijitpaul0212
1 Replies

5. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

6. Shell Programming and Scripting

need to kill a number of processes with name "XYZ" at a time using shell script

Hi, when i grep for the process "XYZ" , there will be some good number of processes with that name, i want to kill all the these processes at a time using shell script? Any help needed for this action. Thanks Regards, Anil (6 Replies)
Discussion started by: anilmanepu
6 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Programming

do you believe X-application will "kill" the CDE and come back to login dialog

1 . Thanks you for reading the letter 2 . I have programe a X-application .Sometimes, I run it from terminal of CDE ,it "kill" the CDE and I meet the login dialog . I debug it . I find that the SIGHUP caused the X-app died .I do not run it from terminal of CDE ,I run it "click button" from panel ,... (3 Replies)
Discussion started by: chenhao_no1
3 Replies
Login or Register to Ask a Question