UNIX系统高负载邮件报警脚本

本文介绍了一个HP-UX 11.11系统中用于监控数据库负载并追踪顶级SQL语句的Shell脚本。该脚本通过top命令获取系统负载,并使用grep、awk等工具筛选出关键SQL语句及其相关信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

###########################
#OS: HP-UX 11.11
###########################

#!/bin/sh

###########################
#Input your env parameters
###########################

sourcepath=/dbashell/top_sql_trace_log
user=test
pass=test
file=$sourcepath/topsql_`date +%E%m%d_%H%M%S`

[@more@]

top -d 1 -f $sourcepath/tmp_top.log
grep Load $sourcepath/tmp_top.log|awk '{print $3}'|read lav
expr substr $lav 1 1|read p1
expr substr $lav 3 2|read p2
echo $p1$p2|read lav

if test $lav -lt 150; then #当load>1.5报警,可以自行修改
rm $sourcepath/tmp_top.log
exit 0
fi

cp $sourcepath/tmp_top.log $file.log
grep "oraclehpehr2" $sourcepath/tmp_top.log|head -10|awk '{print $3}' > $sourcepath/tmp_top.list
cat $sourcepath/tmp_top.list | while read pid
do
echo "select b.spid, a.sid, a.program, a.machine, c.event from v$session a, v$process b, v$session_wait c" >> $file.sql
echo "where a.paddr=b.addr and b.spid="$pid" and c.sid=a.sid;" >> $file.sql
echo "select a.sid,b.sql_text from v$session a, v$sqltext b, v$process c " >> $file.sql
echo "where c.spid="$pid" and a.paddr=c.addr and b.hash_value=a.sql_hash_value order by a.sid,b.piece;" >> $file.sql
done

sqlplus -s $user/$pass <$sourcepath/tmp_top.log
set linesize 200
set trims on
col spid for a5
col program for a30
col machine for a30
col event for a30
spool $file.tmp
start $file.sql
spool end
exit;
EOF

cat $file.tmp >> $file.log
rm $file.tmp
rm $file.sql
rm $sourcepath/tmp_top.log
rm $sourcepath/tmp_top.list
rm end.lst

mailx -s "Server_OverLoad" aluworlds@163.com < $file.log

exit 0

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7319461/viewspace-928343/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7319461/viewspace-928343/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值