LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-07-2006, 01:23 PM   #1
Melsync
Member
 
Registered: Sep 2005
Posts: 75

Rep: Reputation: 15
capture the output to a variable


I want to assign the value of a certain pid in order to kill it in a script
Quote:
echo `ps ux | grep dhcpcd | grep -v grep` | cut -d' ' -f2`
gets me the pid number, and only that, all right but then
Quote:
pidno=`echo `ps ux | grep dhcpcd | grep -v grep` | cut -d' ' -f2``
returns 'command not found' and
Quote:
pidno="echo `ps ux | grep dhcpcd | grep -v grep` | cut -d' ' -f2`"
returns the whole string of the output of the command ps.
How can I put the single number in a variable?
Thanks.
 
Old 09-07-2006, 01:27 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i'm guessing you've not heard aboput the pidof command?
Code:
pidno=$(pidof dhcpcd)
as far as where you're going wrong... take out all the echo stuff. you need to echo it to show the output as a command but you don't need it to assign the output to a vairable.
Code:
pidno=$(ps ux | ... )

Last edited by acid_kewpie; 09-07-2006 at 01:28 PM.
 
Old 09-07-2006, 01:51 PM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Other than typo in dhcpd ( dhcpcd ) I would go with
Code:
pidno=$(pidof dhcpd)
echo $pidno
1995
With correct spelling this works also
Code:
pidno=$(echo `ps ux | grep dhcpd | grep -v grep` | cut -d' ' -f2)
echo $pidno
1995
 
Old 09-07-2006, 02:15 PM   #4
Melsync
Member
 
Registered: Sep 2005
Posts: 75

Original Poster
Rep: Reputation: 15
Thank you, all four solutions work.
Btw, homey, the process is not a typo; I'm using this program: dhcpcd at freshmeat
Thanks again.
 
Old 09-07-2006, 02:17 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by Melsync
Thank you, all four solutions work.
Btw, homey, the process is not a typo; I'm using this program: dhcpcd at freshmeat
Thanks again.
hehe, bless. dhcpd = dhcp server daemon. dhcpcd = dhcp client daemon.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script- capture cdparanoia text output code-breaker Linux - Software 7 08-03-2006 10:13 PM
can't capture 'at' command standard output to a file bartoni Linux - General 3 02-28-2006 03:52 PM
Capture 'make' Output to File Kenji Miyamoto Linux - Software 4 05-23-2005 05:56 PM
insert output of sed into a variable hwouters Linux - General 3 11-06-2004 07:54 PM
capture make's output gboutwel Linux - Newbie 2 07-07-2002 05:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:52 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
Open Source Consulting | Domain Registration