pugna
全部博文(171)
分类: 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