Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1055786
  • 博文数量: 171
  • 博客积分: 55
  • 博客等级: 民兵
  • 技术积分: 2077
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-04 10:11
个人简介

pugna

文章分类

全部博文(171)

文章存档

2021年(4)

2020年(1)

2019年(4)

2018年(5)

2017年(7)

2016年(9)

2015年(36)

2014年(8)

2013年(96)

2012年(1)

分类: Oracle

2013-07-20 13:33:35

原文地址:Oracle awr每天定时执行 作者:随风飘云

Crontable的设置:

30 23 * * * /bin/bash /usr/local/bin/orahtml.sh 每天晚上23点30分执行:


AWR分析脚本:



#Data: 2013/02/25
#Name:Gavin
#Mail:wkgbc456@163.com
mail=151xxxxxxxx@139.com
export ORACLE_BASE=/disk02/oracle
export ORACLE_SID=capitalv
export ORACLE_HOME=$ORACLE_BASE/oracle/product/10.2.0/db_1
PATH=/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:$PATH;
export PATH=$PATH:$ORACLE_HOME/bin
export PATH
DIRECTORY=/disk02/oracle/html
HTML=ora104_awrrpt_`date +%Y%m%d`.html

############DIRECTORY####
if [ ! -d $DIRECTORY ];then
   echo "The $DIRECTORY is  not exsit";
   exit
fi
cd $DIRECTORY
if [ -f $HTML ];then
  rm -rf $HTML;
fi
#######anyalse oracle web#####
sqlplus /nolog</dev/null
connect / as sysdba
set heading off
spool tempfile.tmp
select min(SNAP_ID) from dba_hist_snapshot;
spool off
!
MINSNAPID=`cat tempfile.tmp|grep -v "SQL>" |grep -v ^$`
 
sqlplus /nolog</dev/null
connect / as sysdba
set heading off
spool tempfile.tmp
select max(SNAP_ID) from dba_hist_snapshot;
spool off
!
MAXSNAPID=`cat tempfile.tmp|grep -v "SQL>" |grep -v ^$`
 
echo "$HTML" >tempfile.tmp
REPORT_NAME=`cat tempfile.tmp`
rm -rf tempfile.tmp
 
echo "define num_days = 1">awrrpt_tmp.sql
echo "define report_type = 'html'">>awrrpt_tmp.sql
echo "define begin_snap = $MINSNAPID">>awrrpt_tmp.sql
echo "define end_snap  = $MAXSNAPID">>awrrpt_tmp.sql
echo "define report_name = '$REPORT_NAME'">>awrrpt_tmp.sql
echo "@@?/rdbms/admin/awrrpt" >>awrrpt_tmp.sql
 
sqlplus /nolog</dev/null
connect / as sysdba
@awrrpt_tmp.sql
!


###########scp web html####################
scp $HTML gavin@192.168.21.50:/var/www/html/oracle/
if [ $? = 0 ] ;then
   echo "Oracle'analyse scp successfully" |mail -s "Oracle analyse" $mail
else
  echo "scp not successfully"|mail -s "Oracle analyse" $mail
fi



                                   
阅读(2502) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~