利用139的郵箱,把自已定製的數庫警告發到139郵箱並同時發到手機裡
cat /home/oracle/send_warning.sh
#!/bin/sh
DB_USER=test #DB USER
DB_PWD=test #DB PASSWORD
DB_SERV=test #DB SERVICE NAME
rm -rf /home/oracle/warning.txt
send_day=`sqlplus -s <exec p_get_warning;
set time off
set heading on
set linesize 300
set trimspool on
col session_count 999999
col sys_time a20
col owner format a20
col object_name format a20
col sid format 999999999
col serial# format 999999
col ctime format 999999
col action a70
spool /home/oracle/warning.txt
prompt -------------------------The number of current connection:------------------;
select * from db_warning_session;
prompt -------------------------The information about the locking:-----------------;
select * from db_warning_lock;
spool off
/
!`
a=`cat /home/oracle/warning.txt |wc -l`
if [ $a -gt 8 ]
then
echo "database warning"|mutt -s "database waring" -a /home/oracle/warning.txt
fi
說明:$a -gt 8的目的是當/home/oracle/warning.txt大於8行的時候說明資料庫已經有警告資訊了,這個時候才發郵件。這個值是自己依據空記錄時定的,如下說明沒有資訊
-------------------------The number of current connection:------------------
no rows selected
-------------------------The information about the locking:-----------------
no rows selected
以下為p_get_warning的內容,只監控session數和lock狀態。
sys使用者把一些字典授權給test
create view v_sys_session as select * from v$session;
create view v_sys_lock as select * from v$lock;
create view v_sys_dba_objects as select * from sys.dba_objects ;
create view v_sys_locked_object as select * from v$locked_object;
grant select on v_sys_session to test;
grant select on v_sys_lock to test;
grant select on v_sys_dba_objects to test;
grant select on v_sys_locked_object to test;
-- Create table
create table DB_WARNING_LOCK
(
OWNER VARCHAR2(50),
OBJECT_NAME VARCHAR2(50),
SID NUMBER,
SERIAL# NUMBER,
CTIME NUMBER,
ACTION VARCHAR2(50)
)
;
comment on table DB_WARNING_LOCK
is '當前資料庫鎖定物件表';
-- Add comments to the columns
comment on column DB_WARNING_LOCK.OWNER
is '物件歸屬';
comment on column DB_WARNING_LOCK.OBJECT_NAME
is '物件名';
comment on column DB_WARNING_LOCK.SID
is 'SID';
comment on column DB_WARNING_LOCK.SERIAL#
is '序列';
comment on column DB_WARNING_LOCK.CTIME
is '鎖定時長單位 秒';
comment on column DB_WARNING_LOCK.ACTION
is '解決方法';
-- Create table
create table DB_WARNING_SESSION
(
SESSION_COUNT NUMBER,
SYS_TIME DATE
);
-- Add comments to the table
comment on table DB_WARNING_SESSION
is '當前資料庫連數';
-- Add comments to the columns
comment on column DB_WARNING_SESSION.SESSION_COUNT
is '當前連線數';
comment on column DB_WARNING_SESSION.SYS_TIME
is '當時時間';
*/
create or replace procedure p_get_warning is
v_cn number;
begin
delete from db_warning_session;
delete from db_warning_lock;
execute immediate 'select count(*) from v$session'
into v_cn;
if v_cn > 500 then
insert into db_warning_session values (v_cn, sysdate);
end if;
insert into db_warning_lock
select b.owner, b.object_name, c.sid SID, e.serial#, c.ctime, null
from sys.v_sys_locked_object a,
sys.v_sys_dba_objects b,
sys.v_sys_lock c,
dba_blockers d,
sys.v_sys_session e
where a.object_id = b.object_id
and a.session_id = c.sid
and c.sid = d.holding_session
and d.holding_session = e.sid
and c.type = 'TX'
order by ctime desc;
update db_warning_lock a
set a.action = 'alter system kill session ' || '''' || a.sid || ',' || a.serial# || '''';
commit;
end p_get_warning;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/67798/viewspace-1030759/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 安卓手機上設定139郵箱賬號安卓
- linux mail利用外部郵箱地址發郵件LinuxAI
- 利用godaddy的cpanel郵箱伺服器的smtp發郵件Go伺服器
- 檢測郵箱是否是QQ郵箱並給出提示
- qq郵箱怎麼發檔案給別的郵箱 qq郵箱如何將文件傳送給別人
- 網易郵箱的CSS開發(一)CSS
- 把企業郵箱換成Zoho Mail企業郵箱之前的疑問AI
- 電子郵箱是qq郵箱嗎 電子郵箱和qq郵箱的區別聯絡介紹
- win10自帶郵件怎麼新增qq郵箱_win10郵箱如何匯入qq郵箱Win10
- win10自帶郵箱無法登入QQ郵箱Win10
- iphone 6s自帶郵箱收發郵件設定教程iPhone
- win10系統自帶郵箱發不出去郵件怎麼辦_win10郵箱發不出去郵件解決方案Win10
- 網易推出手機號碼郵箱:知道手機號即可發郵件
- Laravel 配置郵箱引數Laravel
- gitlab郵箱驗證 郵箱提醒設定Gitlab
- Windows10系統自帶郵箱不能同步qq郵箱怎麼辦Windows
- 蘋果郵箱地址蘋果
- win10 email配置qq郵箱如何操作_win10郵箱怎麼新增qq郵箱Win10AI
- win10使用自帶郵箱傳送郵件時直接進傳送箱裡無法完成傳送怎麼解決Win10
- win10自帶的郵箱軟體無法同步網易163郵箱如何解決Win10
- 個人郵箱與企業郵箱的區別有哪些?如何選擇?
- 用python開啟女同學的電腦攝像頭,並把影像傳回qq郵箱Python
- VNPY利用郵件引擎,把引數最佳化結果作為附件傳送給預定郵箱
- win10在哪裡刪除郵箱帳號_win10郵件中如何刪除郵箱賬戶Win10
- PHP中的郵箱驗證PHP
- golang傳送郵件(qq郵箱)Golang
- win10系統下郵箱怎麼新增qq郵箱Win10
- 如何申請企業郵箱?企業郵箱選購指南
- 工作郵箱怎麼註冊?企業郵箱有哪些功能?
- node.js開發網站直接提交留言到固定郵箱Node.js網站
- win10郵件怎麼用qq郵箱 win10郵件如何使用qq郵箱Win10
- google smtp 郵箱配置Go
- js驗證郵箱JS
- Mac電子郵箱Mac
- gitlab 郵箱配置Gitlab
- python清空郵箱Python
- Javascript郵箱驗證JavaScript
- repo 修改郵箱地址