LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Pass output of one command as input to another on bash (http://www.linuxquestions.org/questions/linux-newbie-8/pass-output-of-one-command-as-input-to-another-on-bash-695763/)

linuxlover.chaitanya 01-08-2009 01:01 AM

Pass output of one command as input to another on bash
 
Hello all,

I have a script that starts ifstat process everytime that script is run. I want to kill all the ifstat processes running.
I know I can get the process ids by pidof command. I want to pass the output of this command to kill so that all the processes are killed.
Is there anyway I can do this?
Like
pidof ifstat. I get some pids then I pass these pids to kill.
I need to do this on bash first and then if this works for me I will use it in script for ifstat is running unnecessarily.

Didier Spaier 01-08-2009 01:19 AM

You ca do this
pidof <program_you_want_to_kill>|xargs kill

As usual you can know more with man <command> or info <command>.

I must admits that the output of "man bash" may be difficult to swallow at once ... So you will find guides you need at The Linux Documentation Projects.

To begin with I would suggest reading "Introduction to Linux - A Hands on Guide" from Machtelt Garrels.

colucix 01-08-2009 01:37 AM

You can also use a single command: pkill. Suppose you want to kill the processes using SIGABRT: you can do
Code:

pkill -SIGABRT ifstat
use either the signal name or its numeric id. To get a list of all the signals, take a look at
Code:

man 7 signal

jschiwal 01-08-2009 01:46 AM

There is also killall which will kill all processes by name.
ex:
killall -SIGQUIT ifstat


All times are GMT -5. The time now is 12:58 PM.