Sam Carleton
Ok, I have a problem. I am running a server that forks left and right, once it is running, there are often 40+ processes running. 'ps ax | grep <path>' will display on the processes in question, now I would like to extend this command line to be able to kill all the processes with on command.
I know how to do basic things in bash, but I don't know how to take the output from the 'ps ax | grep %1' and get only the first string of the second line, which is the PID. I plan to do a 'ps ax | grep %1' before each kill because sometimes when you kill PID 4, it will terminate PID 5 through 9.
Using awk it's very easy to single out specific columns. For example, ps ax | grep <path> | awk '{ print $1; }' will print the PID (first column of the ps output) of all processes selected by grep. Remember to use single quotes (') for the argument of awk. The use of double quotes (") would result in $1 beeing expanded by the shell. You can extend the awk script to print only one specific row: ps ax | grep <path> | awk 'NR == 1 { print $1; }' will print only the PID of the first process selected by grep. Eilert -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Eilert Brinkmann -- Universitaet Bremen -- FB 3, Informatik eilert@informatik.uni-bremen.de - eilert@tzi.org - eilert@linuxfreak.com http://www.informatik.uni-bremen.de/~eilert/ -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/