1834137 Members
2386 Online
110064 Solutions
New Discussion

Need A Script

 
Faizer
Advisor

Need A Script

Hi Gurus
I have a script in the cron that shutsdown my Database. I have now found that the database does not go down and needs manual intervention to kill some of the hanging processess.

The ps -ef give the following output
orasag 7454 1 2 05:51:57 ? 0:04 oracleSAG (LOCAL=NO)
orasag 6515 1 0 05:45:50 ? 0:03 oracleSAG (LOCAL=NO)
orasag 6700 1 0 05:45:54 ? 0:59 oracleSAG (LOCAL=NO)
orasag 7262 1 0 05:49:57 ? 0:04 oracleSAG (LOCAL=NO)
orasag 7274 1 2 05:49:58 ? 0:13 oracleSAG (LOCAL=NO)
orasag 6648 1 2 05:45:53 ? 0:03 oracleSAG (LOCAL=NO)
orasag 6818 1 0 05:46:01 ? 0:00 oracleSAG (LOCAL=NO)
orasag 6824 1 0 05:46:01 ? 0:11 oracleSAG (LOCAL=NO)
orasag 7096 1 0 05:47:56 ? 0:04 oracleSAG (LOCAL=NO)
orasag 6682 1 0 05:45:54 ? 0:58 oracleSAG (LOCAL=NO)
orasag 6533 1 0 05:45:50 ? 0:03 oracleSAG (LOCAL=NO)
orasag 7256 1 0 05:49:56 ? 0:00 oracleSAG (LOCAL=NO)
orasag 6768 1 0 05:45:56 ? 0:04 oracleSAG (LOCAL=NO)
orasag 6732 1 0 05:45:55 ? 0:00 oracleSAG (LOCAL=NO)

I need a script that could identify all PID's for the processess that belong to orasag and where LOCAL=NO and perform a 'kill -9 ' for those PIds.

thankyou in advance
Faizer
11 REPLIES 11
H.Merijn Brand (procura
Honored Contributor

Re: Need A Script

is

# perl -MProc::ProcessTable -e'$x=getpwnam"orasag";kill 9,map{$_->pid}grep{$_->uid==$x&&$_->cmndline=~/LOCAL=NO/)@{Proc::ProcessTable->new()->table}'

too terse?

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
G. Vrijhoeven
Honored Contributor

Re: Need A Script

Hi Faizer,

How about:

kill -9 $(ps -ef | grep -v grep | grep "LOCAL=NO" | awk '/oracleSAG/ {print $2}')

Check this first, before adding the kill -9 string, to make sure i did not make a typo.

HTH,

Gideon
H.Merijn Brand (procura
Honored Contributor

Re: Need A Script

Nice one Gideon, but you forgot the "user" part:

kill -9 $(ps -ef | grep -v grep | grep ^orasag | grep "LOCAL=NO" | awk '/oracleSAG/ {print $2}')

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
G. Vrijhoeven
Honored Contributor

Re: Need A Script

Procura,

Thanks for the correction.

Gideon
Faizer
Advisor

Re: Need A Script

Please note that I am geeting the folloiwng error.
syntax error The source line is 1.
The error context is
>>> oracleSAG/{ <<<
awk: Quitting
The source line is 1.
best regards
Jannik
Honored Contributor

Re: Need A Script

#!/usr/bin/ksh

for i in $(ps -ef | grep -v grep | grep orasag | grep oracleSAG | grep | grep 'LOCAL=NO' | awk '{print $2}')
do
kill -9 $i
done
jaton
G. Vrijhoeven
Honored Contributor

Re: Need A Script

Hi Faizer,

Try a space between / and {

HTH,

Gideon
Sanjay Kumar Suri
Honored Contributor

Re: Need A Script

Check V$session view to find more on this. These are Oracle active/inactive sessions. Following sql can help:

SELECT SID, SERIAL#, STATUS, SERVER, USERNAME FROM V$SESSION

If a user session is processing a transaction (ACTIVE status) when it is terminated, the transaction is rolled back and the user immediately receives the following message:

ORA-00028: your session has been killed

If the session is not making a SQL call to Oracle (is INACTIVE) when it is terminated, the ORA-00028 message is not returned immediately.

Check the following link as well:
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96521/manproc.htm#3849

Have a look at tnsnames.ora also.

sks


A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Faizer
Advisor

Re: Need A Script

Hi every one
Thankyou for the time spent on this. Both the scripts provided worked.

Thanks a lot
Faizer
Michael Schulte zur Sur
Honored Contributor

Re: Need A Script

Faizer,

please have a look at this:
http://forums1.itrc.hp.com/service/forums/helptips.do?#28

thanks,

Michael
GIRIJA SWAIN
Advisor

Re: Need A Script

Faizer,
I was also looking for a similar script. Thank you and all for this great help. Can you give points to all these helpfull guys.
GSS-PALO-ALTO