LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   kill < file (Feeding kill from file), PID, <, awk, grep (http://www.linuxquestions.org/questions/programming-9/kill-file-feeding-kill-from-file-pid-awk-grep-800920/)

jaffd 04-08-2010 11:49 PM

kill < file (Feeding kill from file), PID, <, awk, grep
 
Hi, In a script I have written, I have extracted a couple of processes by using (ps -ef) and (grep) and placed them in a file called (kill_PID). Then after using (awk) I am left with 2 PID's that I need to feed to (kill) command. Here is the scenario simplified:

File called (kill_PID) has 1 column with 2 values, lets give them the following values:

9645
9646

What do I need to add to my script in order to extract these to values from file (kill_PID) and feed them into kill command in order to kill both PID's.

I tried

kill < kill_PID

But this did not work. Feedback is appreciated.

bakdong 04-09-2010 12:09 AM

You could use something like:

while read a ; do kill $a; done < kill_PID

You can use process names with some versions of kill. Also have you looked at 'killall'?

grail 04-09-2010 01:29 AM

Or instead of having awk waste time putting them into a file just use it to execute the kill command:

Code:

awk '<whatever you have so far>{print | "kill " <number you got from previous stuff>}'

jaffd 04-09-2010 04:07 PM

bakdong > thank you for the (while) loop it fixed my problem and now I know how to read input from a file. I will also check out (killall).

grail > thanks, I thought about using (awk) all the way, but I need more time to master syntax and various options.

unSpawn 04-09-2010 05:06 PM

Quote:

Originally Posted by jaffd (Post 3929392)
I have extracted a couple of processes by using (ps -ef) and (grep) and placed them in a file (..) Feedback is appreciated.

ps|grep|kill kludges may be necessary in some cases but next time try using 'pkill' instead?


All times are GMT -5. The time now is 01:30 PM.