1833875 Members
1848 Online
110063 Solutions
New Discussion

Re: script comment

 
kholikt
Super Advisor

script comment

I am writing a script to oracle rman process. Sometimes when the rman is killed it must sprawn another one. I want to have some comment whether my script still has any loop hole as I do not want to kill the wrong oracle process.

#!/usr/bin/sh

process='/app/oracle/product/9.2.0.2.0/bin/rman'
count='1'
limit='4'
PID=`ps -ef | grep "$process" | grep -v grep | grep -v ps | cut -c10-14 | sort -r`

function kill_rman
{
if [ -z "$PID" ];
then
echo "No process to kill"
else
echo kill -9 $PID
fi
}

while [ "$count" -lt "$limit" ]
do
echo "$count"
count=$(($count+1))
kill_rman
sleep 20
done
abc
5 REPLIES 5
Muthukumar_5
Honored Contributor

Re: script comment

Yes.

You have written to kill the process only not starting if it is killed already.

In this script,

#!/usr/bin/sh

process='/app/oracle/product/9.2.0.2.0/bin/rman'
count='1'
limit='4'

function kill_rman
{
# It should be here to keep on checking process ID dynamically.
PID="`ps -ef | grep "$process" | grep -v grep | grep -v ps | cut -c10-14 | sort -r`"

if [ -z "$PID" ];
then
echo "No process to kill"
else
echo kill -9 $PID
fi
}

while [ "$count" -lt "$limit" ]
do
echo "$count"
count=$(($count+1))
kill_rman
sleep 20
done

# end
exit 0

##########

If you want to have scripting guidance then feel free to give full requirement so that you will get PERFECT solution(s) ;)

-Muthu

Easy to suggest when don't know about the problem!
Jean-Yves Picard
Trusted Contributor

Re: script comment

hello,

instead of the long
ps -ef | grep "$process" | grep -v grep | grep -v ps | cut -c10-14 | sort -r

you might wish to
export UNIX95=XPG4
then
ps -ef -o pid,args | awk '$2=="'$process'" { print $1}'

Muthukumar_5
Honored Contributor

Re: script comment

Picard,

I hope,

ps -ef -o pid,args | awk '$2=="'$process'" { print $1}'

will not work?

you have to export $process variable with awk as,

awk -v var=$process so that var can be used for if look.

-Muthu
Easy to suggest when don't know about the problem!
Ivan Ferreira
Honored Contributor

Re: script comment

You can also use ps -u oracle to reduce the list of process. But I think that the output does not return the full path.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
James R. Ferguson
Acclaimed Contributor

Re: script comment

Hi:

PLEASE do not kill processes beginning with 'kill-9'. This signal is not catchable and does not therefore offer a process any chance to remove its temporary files and/or shared memory segments!

This has been discussed many, many times in this Forum; perhaps the most recent here:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=969402

Secondly, use the technique Jean-Yves has shown leveraging the UNIX95 (XPG4) behavior to EXACTLY select a process in question. The essential change I would make, however, is *not* to export the UNIX95 variable but rather set it *only* for the duration of the 'ps' command, thusly:

# UNIX95= ps -e -o ...

Note the space character after the "=" and before the 'ps'. This keeps the UNIX95 variable from applying to any commands *but* the one on the line on which it occurs.

The link above also shows another example of finding processes this way.

Regards!

...JRF...