Oracle shell监控小脚本

此博客为转载内容,原链接为https://www.cnblogs.com/xibuhaohao/p/10912000.html ,涉及shell、数据库和awk等信息技术领域内容。

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

cat dba_cpu_monitor.sh   
##CPU Monitor
h=`hostname`
cpu_used=`top -b -d 1 -n 2 | grep Cpu | awk 'NR>1'`
user_cpu_used=`echo $cpu_used|awk '{print $2}'`
sys_cpu_used=`echo $cpu_used|awk '{print $4}'`
io_cpu_used=`echo $cpu_used|awk '{print $10}'`
idle_cpu=`echo $cpu_used|awk '{print $8}'`
b=50
c=$(echo "$user_cpu_used >$b"|bc)
if [ $c -eq 1 ]
then
 # echo "Please check SQL!"
  echo "CPU Used $user_cpu_used% Over 25%,Please Check,$h!"
else
echo "OK"
fi
 
 
cat dba_oracle_listener_monitor.sh
#Oracle listener check
h=`hostname`
v_l=`ps -ef|grep ora|grep LISTENER|grep -v grep|awk '{print $2}'`
if [ ! -n $v_l ]; then
  #echo "IS Wrong!"
  echo "Oracle LISTENER is Down,Please Check,$h!"
else
  #echo "Listener Status IS OK!"
  echo "OK"
fi
 
 
cat dba_oracle_status_monitor.sh
#Oracle status check
v_s=`ps -ef|grep ora|grep ora_smon|grep -v grep|awk '{print $2}'`
h=`hostname`
if [ ! -n $v_s ]; then
  #echo "IS Wrong!"
  echo "Oracle DB is Down,Please Check,$h!"
else
  #echo "Oracle Status IS OK!"
  echo "OK"
fi
 
 
cat dba_session_monitor.sh
source ~/.bash_profile
##Oracle session
h=`hostname`
k="set heading off feedback off pagesize 0 verify off echo off"
t="v\$session"
v_session=`sqlplus -s dbadmin/QazWsx12  << EOF
$k
SELECT count(1) FROM $t s where s.STATUS='ACTIVE' and s.TYPE='USER';
EOF`
#echo v_session
if [ $v_session -gt 15 ]
then
  echo "Oracle Active session $v_session Over 15,Please Check,$h!"
else
echo "OK"
fi
 
 
cat dba_tablespace_monitor.sh
source ~/.bash_profile
##Oracle tablesapce
h=`hostname`
k="set heading off feedback off pagesize 0 verify off echo off"
t="dba_users"
v_tab_used=`sqlplus -s dbadmin/QazWsx12  << EOF
$k
select * from (
select
case
when s.USED_PERCENT<95 then 'OK'
  else 'Tablespace '||s.TABLESPACE_NAME||' Used '||round(s.USED_PERCENT,2)||'%,'||'Please Check!'
end status
from
dba_tablespace_usage_metrics s where s.TABLESPACE_NAME in ('PAYIDX','USERS','UNDOTBS1')) a where status !='OK';
EOF`
#echo v_tab_used
if [ -n "$v_tab_used" ]
then
  echo "$v_tab_used","$h"
else
  echo "OK"
fi
 
 
cat dba_user_lock_monitor.sh
source ~/.bash_profile
##Oracle session
h=`hostname`
k="set heading off feedback off pagesize 0 verify off echo off"
t="dba_users"
v_user_lock=`sqlplus -s dbadmin/QazWsx12  << EOF
$k
SELECT s.username,s.account_status FROM $t s where s.username in ('BOSS','ISMP','TEMP_DSF','PAY','ACCOUNT','SETTLE','TESTUSER') and s.account_status !='OPEN';
EOF`
#echo $v_user_lock
if [ -n "$v_user_lock" ]
then
  echo "$v_user_lock ,Please Check,$h!"
else
echo "OK"
fi
 
 

转载于:https://www.cnblogs.com/xibuhaohao/p/10912000.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值