Excluding grep from process list
grep's -v
switch reverses the result, excluding it from the queue. So make it like:
ps aux | grep daemon_name | grep -v "grep daemon_name" | awk "{ print \$2 }"
Upd. You can also use -C
switch to specify command name like so:
ps -C daemon_name -o pid=
The latter -o
determines which columns of the information you want in the listing. pid
lists only the process id column. And the equal sign =
after pid
means there will be no column title for that one, so you get only the clear numbers - PID's.
Hope this helps.
You can use a character class trick. "[d]" does not match "[d]" only "d".
ps aux | grep [d]aemon_name | awk "{ print \$2 }"
I prefer this to using | grep -v grep
.
Avoid parsing ps
's output if there are more reliable alternatives.
pgrep daemon_name
pidof daemon_name