LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-25-2008, 12:49 AM   #1
jkarp2112
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Rep: Reputation: 0
Send file output to 'kill' command


Would like to send the output of a text file, in this case a process id, to the 'kill' command so, well, that process would be kill'd

example: if i 'cat something.pid' it outputs the process id i'd like to kill.

of course i could manually do this bit i would like to put it into a bash script.

much tia. - jeff
 
Old 06-25-2008, 01:33 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
pid=`cat something.pid`
kill $pid

or even

kill `cat something.pid`

or

use $() instead of backticks thus

pid=$(cat something.pid) etc etc
 
Old 06-25-2008, 02:02 AM   #3
bhert
Member
 
Registered: May 2006
Distribution: OpenSUSE 10.3 Kubuntu Hardy Heron
Posts: 268

Rep: Reputation: 30
I use the script below to kill 3 or 4 numbered process to kill the ones I spawn. Mostly I use it if firefox crashes.

I named the script bomb for fun and put it in my path.

If firefox acts funny, I just type bomb firefox and it's gone.

#!/bin/bash
#script to kill process quickly

kill -9 `ps -e | grep "$*" | cut -d " " -f1` 2>/dev/null || kill -9 `ps -e | grep "$*" | cut -d " " -f2`



-bhert

Last edited by bhert; 06-25-2008 at 02:03 AM.
 
Old 06-25-2008, 11:27 AM   #4
jkarp2112
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Excellent - i'll use both to build my script!

thanks everyone, this really helped !!
 
Old 06-25-2008, 06:17 PM   #5
solarkash
LQ Newbie
 
Registered: Jun 2008
Posts: 11

Rep: Reputation: 1
I'd prefer the xargs

Quote:
cat something.pid | xargs kill
 
  


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
send output of namp scan to CSV file rsmccain Linux - Networking 11 04-18-2009 09:31 PM
Make a program can collect linux command output regularly and send to a tftp server fragon Programming 2 04-07-2008 05:49 PM
IS it possible to send command output to a file as well as the screen helptonewbie Programming 6 09-16-2007 02:13 PM
Send ALL output streams to file? Nuvious Linux - General 1 04-22-2007 03:08 PM
Help: Command Output to File. rvijay Linux - Newbie 3 09-30-2003 10:02 AM


All times are GMT -5. The time now is 11:16 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration