自動生成awr報告併發送到郵箱

2021-05-26 13:04:51 字數 2321 閱讀 5950

兩個主要指令碼

生成48小時內awr報告

[oracle@rac1 admin]$ cat myawrrpt.sql

conn / as sysdba;

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;

-- 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)-48 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;

-- print the awr results into the report_name file using the spool command:

column report_name new_value report_name noprint;

select 'awr'||'.'||'&ext' report_name from dual;

set termout off;

spool &report_name;

--awr報告指令碼awrrpt.sql 的核心語句

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

exit

執行awr指令碼並傳送帶附件郵件的python指令碼>crontab -l

30 6 * * * cd /oracle/orabase/admin/awr && ./sendmail.py > sendmail.log 2>&1 &

**:

簡單備份檔案併發送到指定郵箱

一哥們發了個訴求,總覺得自己的伺服器不安全,想搞個定時備份檔案併發送到自己的郵箱 coding utf 8 from future import absolute import,unicode literals import os import datetime import logging imp...

linux 配置mailx傳送到外網郵箱

1 安裝sendmail伺服器 yum install mailx 2 修改配置 vim etc mail.rc 在尾部新增 set from 18765262 139.com 你的郵箱,發件郵箱,例如139郵箱 set smtp smtp.139.com 郵箱的smtp伺服器 set smtp a...

Oracle 每天自動生成AWR報告

經驗豐富的老員工希望能夠每天為資料庫生成1個awr報告,以便於後期分析資料庫的效能變化,手動生成太麻煩,查了一下資料,發現可以自動生成,過程如下。資料庫環境 11gr2 rac 雙節點 awr報告 由於是rac資料庫,希望生成每個節點的報告及全域性報告,時間段為 第一天的0點 第二天的0點。1 在o...