Newbie Question: Killing a process using a supplied name to a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Newbie Question: Killing a process using a supplied name to a shell script
# 1  
Old 04-15-2010
Newbie Question: Killing a process using a supplied name to a shell script

Hi,

I am trying to automate the killing of named processes of which I found a good solution here on the forums but as I am pretty much a begginer to linux I am having an issue. The code I found is:

Code:
kill $(ps -ef | nawk '/monitoreo start/ { print $2}'}

but what I want to do is replace monitoreo with a command line paramter so ideally replace it with $1 which I pass into the script. For the life of me I can't get it to work. Something like:

Code:
kill $(ps -ef | nawk '/$1 start/ { print $2}'}

But to be honest I am not sure if it's even possible. I can't seem to get any parameter declared outwith the backticks to be seen inside them

Can anyone help?

Last edited by Scott; 04-15-2010 at 02:30 PM.. Reason: Please use code tags
# 2  
Old 04-15-2010
Have a look at the pkill command.
# 3  
Old 04-15-2010
I thinks this is because $1 will no longer represent the 1st argument once inside ' '.

---------- Post updated at 09:56 PM ---------- Previous update was at 09:50 PM ----------

Try this

Code:
ps -ef | awk '/'$1' start/ { print $2}'


Last edited by Scott; 04-15-2010 at 02:30 PM.. Reason: Code tags
# 4  
Old 04-15-2010
Thanks will give it a try.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automated Script for Process killing

Hello all, I'm in need of a Script which needs to wait for all the child process to end and then kill the main process. I have a process called mainpp which runs for different instances like evpn, nge, gmn etc so when i query for mainpp process it looks like below. bash-3.2$ ps -eaf |... (6 Replies)
Discussion started by: Mahesh_RPM
6 Replies

2. UNIX for Dummies Questions & Answers

Killing the shell Process

I was just playing with the processes and suddenly a question striked my mind: What will happen if we kill directly the shell process?? :rolleyes: Do anyone know? Will the system shutdown? Or the system wont let it be killed? (5 Replies)
Discussion started by: paras.oriental
5 Replies

3. Programming

need help with shell script filtering files and sort! newbie question?

Hi folks, I would like to get familiar with shell script programing. The first task is: write a shell script that: scans your home-folder + sub-directory for all txt-files that all users of your group are allowed to read and write then output these files sorted by date of last... (4 Replies)
Discussion started by: rollinator
4 Replies

4. Shell Programming and Scripting

**need help for killing a process through script**

Hello All, i hope you are fine. I need a little help from you people-- inside a script i want to kill a parent process by checking it with the child process.. p_pid=`ps -e | awk '/ra_cmd_d/ {print$1}'` here i am selecting the child process id in p_pid. next-- sleep_pid=`ps -af |... (3 Replies)
Discussion started by: onlyniladri
3 Replies

5. Shell Programming and Scripting

script not killing process!

i am using script to connect remotly to server and run some commands , one of these commands is to kill some process but tried different ways with no hope sshpass -p 'pass' ssh -o StrictHostKeyChecking=no server kill -9 `pgrep procs` getting error message "kill: bad argument count" ... (2 Replies)
Discussion started by: mogabr
2 Replies

6. Shell Programming and Scripting

While killing the process, Script gets hanged. Please help me on this.

Hi Everyone, I have written a script to automate the docbase cleanup process on every weekly basis. That is in this script i have to shutdown the docbase and then kill all the process that are hanged except one process(epic process) and need to delete some log files and then i have to start the... (8 Replies)
Discussion started by: Sheethal
8 Replies

7. AIX

killing a process from a script

Hey all. I'm brand new to this forum and am looking for some help. I have a script that verifies that the backup tapes are working correctly. Basically is uses 1 command: restore -xpqvf > rootvglog I use this for each volume group that we have. We run this everyday but the problem is, we... (4 Replies)
Discussion started by: jalge2
4 Replies

8. Shell Programming and Scripting

Killing a process from perl script.

How do I kill a process, say by name "drec" from a perl script. I tried with : ps -eaf | grep drec | awk '{print $2}' | xargs kill -9. The output I got is : ps -eaf | grep drec | awk '{print }' | xargs kill -9 /usr/bin/kill: ipgen: Arguments must be %job or process ids {But, $2 is not... (3 Replies)
Discussion started by: sharuvman
3 Replies

9. Shell Programming and Scripting

killing a child process within a shell

Hi All, I have a written a script in korn shell for importing data into a oracle database. The shell invokes the import within the script. I want to kill this import (child process) . I tries using trap, but this does not kill the import even if i press cnt c. i have to login into other terminal... (2 Replies)
Discussion started by: yerics
2 Replies

10. Shell Programming and Scripting

killing process using a script

can I do ps -ef | grep <process_name> and kill the process is it exists? and send a mail to me that the process was found and killed Thanks much... KS (4 Replies)
Discussion started by: skotapal
4 Replies
Login or Register to Ask a Question