1833875 Members
1998 Online
110063 Solutions
New Discussion

Re: commands needed

 
SOLVED
Go to solution
ng_7
Regular Advisor

commands needed

hi, All,

appreciate if someone could provide the below command.

* grep a process id then kill the process, all command in one line. eg :
when i want to kill some processes with command oralcePROD , i have to : ps -ef |grep oraclePROD, from here i kill -9 PID, is there any command/script which i can run to kill all the oraclePROD process ?

20 REPLIES 20
Dennis Handly
Acclaimed Contributor

Re: commands needed

I'm not sure you ever want to do a kill -9 on Oracle if you can help it.

You could do the following:
# kill -9 $( UNIX95= ps -C oralcePROD -opid= )

(Make sure you test it with an "echo" before the kill.)
ng_7
Regular Advisor

Re: commands needed

hi, Dennis,

i got error message on the command, pls advise.
thanks
Hemmetter
Esteemed Contributor

Re: commands needed

Hi ng

you did simply typo:

oralcePROD instead of oraclePROD.


rgds
HGH
Peter Nikitka
Honored Contributor

Re: commands needed

Hi,

before trying with 'kill', check, which process get reported by the 'ps' - in your case no output was produced, so kill got no process id(s):
Execute
UNIX95= ps -C oralcePROD -opid=

and check for spelling errors.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Luk Vandenbussche
Honored Contributor
Solution

Re: commands needed

ps -ef | grep oraclePROD |awk -F " " '{print $2}' | kill -9
Dennis Handly
Acclaimed Contributor

Re: commands needed

>i got error message on the command,

(It would be more helpful if you just cut n' paste the error rather that attach a bitmap.)

>HGH: you did simply typo:

Oops, I cut n' paste the line with the typo.

You could just redirect stderr so you don't get errors if there aren't any oraclePROD but you sure had a lot. :-)
# kill -9 $( UNIX95= ps -C oraclePROD -opid= ) 2> /dev/null
Dennis Handly
Acclaimed Contributor

Re: commands needed

You haven't assigned any points yet. If our answers were helpful, please see:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33
Peter Nikitka
Honored Contributor

Re: commands needed

Hi,

@Luk:
Since kill won't read its PIDs from stdin, something like
... | kill ..
won't work - you have to use
... | xargs kill ..

Nevertheless the POSIX part of 'ps' is much more reliable, IMHO.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
ng_7
Regular Advisor

Re: commands needed

hi, thanks for you guy response, but i still have some problem on this, please refer to my attachment on my problem. thanks
Hemmetter
Esteemed Contributor

Re: commands needed

Hi ng,

$ ps -ef |grep sam |awk -F "" '{print $2}'|kill â 9

Can not work because kill does NOT read from stdin!

you have to "xargs" the kill command this way:

$ ps -ef |grep sam |awk -F "" '{print $2}'|xargs kill â 9

see xargs(1)


rgds
HGH
Dennis Handly
Acclaimed Contributor

Re: commands needed

As Peter said, you can't do: ... | kill -9

And if you want to see what the ps does, do the following to see why it doesn't kill all:
$ UNIX95= ps -C sam -opid=

From your hard to read bitmap, I see you have a samx (14569) and a shell script running /usr/sbin/sam (14564).

So you can replace sam by samx to get 14569. But you don't want to kill ALL sh's on the system.
Vladimir Fabecic
Honored Contributor

Re: commands needed

for i in `ps -ef | grep oraclePROD |awk -F " " '{print $2}'`
do
kill -9 $i
done
In vino veritas, in VMS cluster
ng_7
Regular Advisor

Re: commands needed

hi, all, my knowleadge fail me again, pls refer to attached file for my problem.

thanks
Dennis Handly
Acclaimed Contributor

Re: commands needed

>pls refer to attached file for my problem.

I can't see why that ps command is failing.
What does this show?
# UNIX95= ps -C oraclePROD

(I can't see your bitmaps accurately enough to tell what your other problems are. Can't you copy just text?
You seem to be echoing $UNIX95 in test.sh instead of echoing $(UNIX95= ps -C oraclePROD)

Note your ps -ef | grep oraclePROD, will find the grep and may kill it. You need to grep -v grep:
# kill -9 $(ps -ef | grep oraclePROD | grep -v grep | awk '{print $2}')
Hemmetter
Esteemed Contributor

Re: commands needed

Hi ng

The last line in your second bitmap, the one giving ">" :

you are just missing the closing ' before |xargs

Again please give the output of
# UNIX95= ps -C oraclePROD


HGH
ng_7
Regular Advisor

Re: commands needed


output for UNIX95= ps -C oraclePROD is :

tamcodb1:/# echo $(UNIX95= ps -C oraclePROD)
PID TTY TIME CMD
Dennis Handly
Acclaimed Contributor

Re: commands needed

>output for UNIX95= ps -C oraclePROD is:
# echo $(UNIX95= ps -C oraclePROD)
PID TTY TIME CMD

Ok, this is saying there are no processes with the basename of oraclePROD. You could try changing it to just "oracle".

This probably occurs because Oracle is fiddling with argv[0] to make it pretty for the users and it no longer matches the real executable.

So it appears you'll need to use your grep solution:
# kill -9 $(ps -ef | grep oraclePROD | grep -v grep | awk '{print $2}')
Rasheed Tamton
Honored Contributor

Re: commands needed

Hi,

ps -ef|awk '/oraclePROD/{print $2}'|xargs -i kill -9 {}

ps -ef|awk '/oraclePROD/{ print "kill -9",$2 }'|sh
ng_7
Regular Advisor

Re: commands needed

hi, thanks for all,i managed to kill all the oraclePROD process by a single command already.
Dennis Handly
Acclaimed Contributor

Re: commands needed

>thanks for all

The proper way to do this is by assigning points. You have not assigned any points yet. Please read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33

You can reopen it with:
http://forums1.itrc.hp.com/service/forums/helptips.do?#41