[SlugBug] Using cut in bash scripts

Neil McGovern maulkin at halon.org.uk
Thu Apr 6 20:14:35 BST 2006


On Thu, Apr 06, 2006 at 07:09:39PM +0100, Bill Best wrote:
> hi there
> 
> just quickly, i would like to extract the process number of the icecast 
> service running here and then give it a variable name:
> 
> >[root at machine ~] ps aux | grep icecast
> >iceadmin  9862  0.0  3.4 339200 17796 pts/126 S   16:04   0:00 icecast -c 
> >/etc/icecast.xml
> >root     10061  0.0  0.1  4444  592 pts/126  R    16:13   0:00 grep icecast
> 
> this is very wrong but might explain what i want the script to do:
> 
> ps aux | grep icecast | cut -f2 > /tmp/icecastproc.$$
> 
> i've tried using cut on the number of characters but no joy as yet.
> 
> i am writing this script to quickly stop and then restart an icecast 
> server after the config file has been changed.
> 
> any ideas?  many thanks in advance and best regards
> 

Well, there's a few ways to tighten this up :)

Try simply:
pidof icecast

Also, in general, to get rid of the grep line when doing a ps, do:
ps aux | grep [s]omeprocess
This'll just match someprocess and not the grep :)

Instead of cut in this example, I'd use
awk '{print $2}'

Neil
-- 
A. Because it breaks the logical sequence of discussion
Q. Why is top posting bad?
gpg key - http://www.halon.org.uk/pubkey.txt ; the.earth.li B345BDD3


More information about the SlugBug mailing list