Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Operating System - Tru64 Unix
Showing results for 
Search instead for 
Did you mean: 

Cut command usage in

Go to solution

Cut command usage in


$ ps -aef |grep mountd*
root 546 1 0.0 Oct 09 ?? 0:00.03 /usr/sbin/mountd -n -i -n
root 562 1 0.0 Oct 09 ?? 0:00.00 /usr/sbin/automount -m /net -hosts -nosuid
root 45657 13758 0.0 10:18:27 pts/0 0:00.01 grep mountd*

My main objective is to check for existing daemon (mountd) runs.If it runs i must kill particular pid's.

Say here i must do "kill -9 546" and kill -9 562". Please let me know how to use CUT or AWK command to kill above two pid's..

Thanks in Advance,

Dennis Handly
Acclaimed Contributor

Re: Cut command usage in

kill -9 $(ps -ef | grep -e "[m]ountd" -e "[a]utomount" | awk '{print $2}')

This works if you have a real shell, ksh. Add "echo" to the beginning to make sure it's correct.

Note: If you were on HP-UX you would never use grep but the -C option:
kill -9 $(UNIX95=ENHANCED_PS ps -opid= -C mountd,automount)
Steven Schweda
Honored Contributor

Re: Cut command usage in

First, what go you think that
grep mountd*
is doing? Hint:
mkdir new_dir
cd new_dir
and try your command again.

Second, you can eliminate your "grep" command
from the "ps" listing by using a popular

urtx# ps -aef | grep [m]ount
root 478 1 0.0 00:31:37 ?? 0:00.00 /usr/sbin/mountd -i
root 493 1 0.0 00:31:38 ?? 0:00.00 /usr/sbin/automount -m /net -hosts -nosuid

Third, I can remember how to use "sed", but
I'd need to read up on "awk" or "cut".

urtx# ps -aef | grep [m]ount | sed -e 's/ *[^ ]* *\([^ ]*\) .*/\1/'

If it's not obvious how to do the "kill"
commands from a list of pid's, then you might
try something like this:

urtx# ps -aef | grep [m]ount | sed -e 's/ *[^ ]* *\([^ ]*\) .*/\1/' | \
while read pid ; do echo kill ${pid} ; done
kill 478
kill 493

When you're happy, remove "echo".

Now that we've solved _that_ problem, what is
the _real_ problem which you are trying to
solve? And why would killing these processes
be the best way to solve it?
Steven Schweda
Honored Contributor

Re: Cut command usage in

And you had better hope that no one else runs
anything which your "grep" will falsely
interpret as one of the processes you're
trying to kill. Or else do a much more
precise search for the processes which you
_really_ wish to kill (user, parent pid, more
complete path, and so on), which would be
harder to do on one line.

> Note: If you were on HP-UX [...]

Yeah. I'd convert all _my_ software to get a
"ps" with that feature.

Re: Cut command usage in


Thanks a lot for time on this..

Closing this thread..