Operating System - HP-UX
1833772 Members
1844 Online
110063 Solutions
New Discussion

Need a shell script help! Tks!

 
SOLVED
Go to solution
violin_1
Advisor

Need a shell script help! Tks!

Dear All,

I need a shell script, I want to monitor top info , pls see attatch top.txt.

We got BAD performance in PROD server ,
because lots of FNDLIBR processes exhausted CPUs and made idle almost 0%.

If top 10 processes include any processes named "FNDLIBR" , I want to get the process id
and execute a select script to check pid status of database:

select status from fnd_concurrent_process
where system_id = PID;
(PID = unix process id)

If returned "Terminated" or "Deactivated" , shell couled exec "kill -9 PID"

The shell flow is :
1.get top info
2.if top 10 processes include any FNDLIBR processes , run a SELECT script
and check its status.
3.if returned status in "Terminated" or "Deactivated" , then kill -9 pid.

If someone knows how to do it ,
please share any tips ,
Apprreciate for any helps.
Thanks in advance!

Violin.
6 REPLIES 6
Simon Hargrave
Honored Contributor
Solution

Re: Need a shell script help! Tks!

Script attached.

Haven't tested it so may need tweaking slightly, but the core functionality is there.

Sounds like a bad thing to do though! Then again, it is Financials ;)
steven Burgess_2
Honored Contributor

Re: Need a shell script help! Tks!

Hi

You need something within the lines of the below

#!/usr/bin/sh

# First send the top output to a file

top -f /tmp/top.out

# Next grep for your pid's and output to file
grep FNDLIBR /tmp/top.out | awk '{print $3}' > /tmp/pids.out

# Do we have a return from the grep
if [ $? != 0 ]
then
exit
else
for i in $(do
export system_id=$i

# within the loop you then need to execute #your select script using system_id variable , #send the output of the select to another #variable and execute kill depending on #outcome

if [ $status = TERMINATED || DEACTIVATED ]
then
kill -9 $status
fi
fi
done

HTH

Steve




take your time and think things through
harry d brown jr
Honored Contributor

Re: Need a shell script help! Tks!


Violin,

You aren't going to be killing terminated processes because they are already terminated.

You really should look into glance/measureware.

live free or die
harry

Live Free or Die
violin_1
Advisor

Re: Need a shell script help! Tks!

Hi Simon,

I'm testing your scripts now , but i got some problems,

I have to run sqlplus in oracle user and kill process in root user,
(If I run sqlplus with root , I'll get error msg like "error.txt")

please check my simon.sh , I could su oracle and run sqlplus for getting process status, but I don't know how to exit and back to root,

I need some help!

Thanks again,
and thanks for all kindly replies!

Violin.
Jean-Louis Phelix
Honored Contributor

Re: Need a shell script help! Tks!

Violin,

A better way to do it would be to use a < su oracle -c 'script' > which would return a PID list to kill.

Oracle script (tstpid.sh) :

for PID in $*
do
# check each status in sqlplus but run with oracle
. /u04/prodora/8.1.7/PROD.env PATH=/opt/java1.3/jre:opt/java/jre:$PATH:/usr/lib:/usr/contrib/bin; export PATH
CONNECT=apps/apps

# Get its status from Oracle and run with oracle account
sqlplus -s $CONNECT >$TMPFILE2 < select process_status_code from fnd_concurrent_processes
where os_process_id = $PID;
EOF

# Check whether output from Oracle says 'Terminiated' or 'Deactivated'
# The status : "K" means "Terminated" , "S" means "Deactivated"
sed 's/K/S/g' $TMPFILE2 | grep -q Terminated

# If it does, kill the beast!
if [ $? -eq 0 ]; then
echo $PID
fi

Then simon.sh could be :

TMPFILE=/tmp/top.tmp
# Get top 10 processes.
top -n 10 -f $TMPFILE
PIDLIST=`cat $TMPFILE | grep FNDLIBR | awk '{print $3}'`
KILLLIST=$(su oracle -c "your_path/tstpid.sh $PIDLIST")
[ -z "$KILLLIST" ] || kill -9 $KILLLIST

Regards.
It works for me (© Bill McNAMARA ...)
violin_1
Advisor

Re: Need a shell script help! Tks!

I've got a solution for killing the FNDLIBR processes.

Now the FNDLIBR processes are all cleaned.

Thanks for all replies.

VIolin.