r0b0tz
music, art, parties, technology, code

I spend a lot of time restarting daemonized ruby processes and need to locate their PIDs on the fly. I got really, really tired of typing all the grep nonsense over and over.

Here is a quick bash script to locate processes by command text.
— begin code –

#!/bin/bash
ps ax | grep "$1" | grep -v grep | grep -v "fp $1"

— end code —

example:

[admin@mon2 scripts]# fp ruby
1160  ? S 09:30   0:15 ruby /scripts/srv.rb
1161  ? S 09:30   0:16 ruby /scripts/test.rb
2583  ? S Jun09   0:06 ruby /scripts/poll.rb
3068  ? S Jun09  71:01 ruby /scripts/diff.rb


Leave a comment or two

This entry was posted on Tuesday, June 10th, 2008 at 2:06 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


2 Comments so far



  1. JD on June 10, 2008 2:50 pm

    the grep -v grep probably works best here, but another neat trick that you can pull, which is nice for ad hoc process grepping is this:


    ps auxww | grep [s]omething

    that will specifically exclude the grep process from the list of matches.

  2. lawrencealan on June 10, 2008 2:54 pm

    nice trickery!

Name (required)

Email (required)

Website

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Feel free to leave a comment

Log in