定時kill長事務指令碼kill_long_session.sh

quanshengaa發表於2016-04-05

定時kill長事務


因為ogg抽取程式需要一定的歸檔,防止歸檔被刪除,所以定時kill長事務,防止抽取程式abend


--kill_long_session.sh
#!/bin/sh
tmpfile0=/oracle/temp/monitor/kill_0.log
tmpfile1=/oracle/temp/monitor/kill_1.log
tmpfile2=/oracle/temp/monitor/kill_2.log
sqlplus / as sysdba <<EOF
spool $tmpfile1
set feedback off
select 'kill time:'||to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') execute_time from dual;
set line 200
set pages 1000
col username for a15
col command for a70
col machine for a20
col terminal for a20
col program for a20
select /*+rule*/ p.spid,s.sid,s.serial#,s.sql_id,s.username,s.machine,s.terminal,s.program
from v\$process p,v\$session s 
where s.paddr=p.addr and s.username<>'SYS' and s.type='USER'
and s.saddr in (select t.ses_addr from v\$transaction t where to_date(t.start_time, 'mm/dd/yy hh24:mi:ss') < sysdate - 5/24);
spool off
EOF
cat $tmpfile1>>$tmpfile0
grep "^[0123456789]" $tmpfile1 |awk '{print $1}'>$tmpfile2
for x in `cat $tmpfile2`
do
kill -9 $x
done
rm $tmpfile1 $tmpfile2



--contab 排程
00 * * * * /oracle/temp/monitor/kill_long_session.sh>>/oracle/temp/monitor/kill_long_session.log

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15797451/viewspace-2075655/,如需轉載,請註明出處,否則將追究法律責任。

相關文章