Oracle AWR报告自动生成并ftp脚本
2013-07-09 14:22
369 查看
脚本主要由以下几个部分组成:
awr.sql 用来在sqlplus 中执行的脚本,该脚本从网上直接找的。
awr.sh 用来调用sqlplus来生成awr报告。
ftp.sh 用来打包压缩每天生成的awr报告(压缩率大于50倍),并进行ftp传输,清理过期的报告,对于linux和solaris略有不同。
crontab 用来执行定时任务,根据需求进行调整。
下面为具体的脚本内容,可以根据需要进行调整。
awr.sql :
awr.sh:
ftp.sh(RHEL6版本):
ftp.sh (Solaris 10版本):
crontab:
awr.sql 用来在sqlplus 中执行的脚本,该脚本从网上直接找的。
awr.sh 用来调用sqlplus来生成awr报告。
ftp.sh 用来打包压缩每天生成的awr报告(压缩率大于50倍),并进行ftp传输,清理过期的报告,对于linux和solaris略有不同。
crontab 用来执行定时任务,根据需求进行调整。
下面为具体的脚本内容,可以根据需要进行调整。
awr.sql :
set echo off; set veri off; set feedback off; set termout on; set heading off; variable rpt_options number; define NO_OPTIONS = 0; -- define ENABLE_ADDM = 8; rem according to your needs, the value can be 'text' or 'html' define report_type='html'; begin :rpt_options := &NO_OPTIONS; end; / variable dbid number; variable inst_num number; variable bid number; variable eid number; begin select max(snap_id)-1 into :bid from dba_hist_snapshot; select max(snap_id) into :eid from dba_hist_snapshot; select dbid into :dbid from v$database; select instance_number into :inst_num from v$instance; end; / column ext new_value ext noprint column fn_name new_value fn_name noprint; column lnsz new_value lnsz noprint; select 'txt' ext from dual where lower('&report_type') = 'text'; select 'html' ext from dual where lower('&report_type') = 'html'; select 'awr_report_text' fn_name from dual where lower('&report_type') = 'text'; select 'awr_report_html' fn_name from dual where lower('&report_type') = 'html'; select '80' lnsz from dual where lower('&report_type') = 'text'; select '1500' lnsz from dual where lower('&report_type') = 'html'; set linesize &lnsz; column report_name new_value report_name noprint; select 'sp_'||:bid||'_'||:eid||'.'||'&ext' report_name from dual; set termout off; spool &report_name; select output from table(dbms_workload_repository.&fn_name(:dbid, :inst_num,:bid, :eid,:rpt_options )); spool off; set termout on; clear columns sql; ttitle off; btitle off; repfooter off; undefine report_name undefine report_type undefine fn_name undefine lnsz undefine NO_OPTIONS
awr.sh:
mydate='date +%y%m%d' ORACLE_SID=orcl; export ORACLE_SID ORACLE_BASE=/opt/app/ora11g; export ORACLE_BASE ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1; export ORACLE_HOME cd /opt/awr $ORACLE_HOME/bin/sqlplus /nolog<<! connect / as sysdba; @awr.sql exit !
ftp.sh(RHEL6版本):
#!/usr/bin/bash mydate=`date +%y%m%d` mydir=/opt/awr cd ${mydir} find *.html -daystart -mtime -1 | xargs tar -zcvf awr_${mydate}.tar.gz echo "======================FTP start=========================" ftp -n<<! open 11.11.11.11 21 user username passwd binary lcd /opt/awr cd /ftp/orcl put awr_${mydate}.tar.gz close bye ! echo "=======================FTP end============================" echo "=================delete the tar file=====================" rm awr_${mydate}.tar.gz echo "=================delete the tar file end=====================" echo "=================delete the old file =====================" find ${mydir} -name "*.html" -type f -mtime +3 -exec rm {} \; echo "=================delete the old file end====================="
ftp.sh (Solaris 10版本):
#!/usr/bin/sh mydate=`date +%y%m%d` mytoday=`date +%m%d` mydir=/opt/awr cd ${mydir} touch ${mytoday}0000 TODAY find *.html -newer TODAY | xargs tar -cvf awr_${mydate}.tar gzip -c awr_${mydate}.tar > awr_${mydate}.tar.gz echo "======================FTP start=========================" ftp -n<<! open 11.11.11.11 21 user username passwd binary lcd /opt/awr cd /ftp/orcl put awr_${mydate}.tar.gz close bye ! echo "=======================FTP end============================" echo "=================delete the tar and temp file=====================" rm awr_${mydate}.tar rm TODAY rm awr_${mydate}.tar.gz echo "=================delete the tar and temp file end=====================" echo "=================delete the old file =====================" find ${mydir} -name "*.html" -type f -mtime +0 -exec rm -rf {} \; echo "=================delete the old file end====================="
crontab:
0 0-23 * * * sh /opt/awr/awr.sh 5 23 * * * sh /opt/awr/ftp.sh
相关文章推荐
- Oracle AWR报告自动生成并ftp脚本
- Oracle AWR 报告 每天自动生成并发送邮箱 Python脚本
- 如何在性能测试中自动生成并获取Oracle AWR报告
- oracle 自动生成 awr 报告的 简单 shell 脚本
- Oracle AWR 报告 每天自动生成并发送邮箱 Python脚本
- 用脚本自动生成AWR报告!
- 【转】Oracle AWR 报告 每天自动生成并发送邮箱 Python脚本(一)
- python脚本自动生成ORACLE AWR报告
- 自动批量生成AWR报告的脚本
- 自动生成awr报告shell脚本--每天早8点到晚12点每四个小时生成一次
- Oracle AWR 报告 每天自动生成并发送邮箱 Python脚本
- Appium跑python脚本自动生成简单测试结果报告
- Linux使用Shell脚本实现ftp的自动上传下载
- [Perl]FTP自动上传文件的脚本以及配置文件
- Hibernate使用自定义脚本替换注解或者xml文件中的自动生成表结构
- 自动化测试之生成测试脚本自动发送邮件(554异常和connection unexpectedly closed)
- ftp自动登陆上传脚本
- 实现自动上传文件到ftp服务器的BAT脚本分享
- 通过ANT实现jmeter批量执行脚本、生成报告、发送邮件全套build.xml文件
- [Perl]FTP自动上传文件的脚本以及配置文件