#!/bin/bash
load=`cat /proc/loadavg | awk '{printf "%d", $1}'`
echo $load
if [ "$load" -gt "1" ]; then
#look_out=`cat /proc/loadavg | awk '{print $5}' `
look_out=`top -n 1 | awk '{print $1}' | sed -n '11,11p'`
echo $look_out
ps -l $look_out >>/data/run/test.log
#check=`ps -l $look_out | awk '{print $14}' | grep -v CMD`
check=`top -n 1 | awk '{print $12}' | sed -n '11,11p'`
echo $check
if [ "$check" = "oracle" ]; then
ORACLE_HOME=/u01/product/oracle;export ORACLE_HOME
ORACLE_SID=orcl;export ORACLE_SID
output=`sqlplus internal
select a.username,a.machine,a.program,b.spid,c.sql_text from v\\$session a,v\\$process b,v\\$sqlarea c where a.paddr=b.addr and c.hash_value=a.sql_hash_value and c.address=a.sql_address and b.spid=$look_out;
exit
EOF
`
echo "$output">>/data/run/test.log
else
echo "NULL"
fi
else
exit 0
fi
此脚本用来记录系统负载升高时占用CPU较高的session。