LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-08-2009, 01:01 AM   #1
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,627

Rep: Reputation: Disabled
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.
 
Old 01-08-2009, 01:19 AM   #2
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-14.1 on a Lenovo T61 6457-4XG
Posts: 4,015

Rep: Reputation: 962Reputation: 962Reputation: 962Reputation: 962Reputation: 962Reputation: 962Reputation: 962Reputation: 962
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.

Last edited by Didier Spaier; 01-08-2009 at 01:19 AM. Reason: Typo
 
Old 01-08-2009, 01:37 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
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
 
Old 01-08-2009, 01:46 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: INPUT/OUTPUT error when remoting in saanjac Linux - Newbie 2 08-08-2008 03:38 PM
how to pass pipe output to file command nickleus Linux - General 6 06-19-2008 06:18 AM
bash input/output redirect problem greno Programming 2 12-31-2006 03:23 PM
bash: cd: /mnt/floppy/: Input/output error embsupafly Linux - Hardware 1 08-16-2003 06:36 AM
How do I pass a C variable to a Bash command ? Linh Programming 6 07-07-2003 03:12 PM


All times are GMT -5. The time now is 09:21 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration