Results 1 to 4 of 4
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 ...
- 04-09-2010 #1Just Joined!
- Join Date
- Sep 2008
- Location
- Washington D.C, USA
- Posts
- 3
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.
ThanksLast edited by jaffd; 04-09-2010 at 03:39 AM. Reason: edit title
- 04-09-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
When you extract the PID's to kill, add "kill " before the PID in "kill_PID". Then you just need to source it, as in ". kill_PID"
Your kill_PID file would look like this:
kill 9645
kill 9646Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 04-09-2010 #3
Sourcing this is kind of a bad idea. Sourcing is more designed for importing variable definitions into the current session.
I also disagree with adding kill to the file.
If you have a list of PIDs and want to kill each of them, things are actually fairly simple:
You would call this script as:Code:#!/bin/bash while readline pid; do kill "$pid" done
This script reads each line of its input and then runs kill with that PID.Code:./kill_script < kill_PID
Do you understand how this script works?DISTRO=Arch
Registered Linux User #388732
- 04-09-2010 #4


Reply With Quote
