ITPub博客

首页 > Linux操作系统 > Linux操作系统 > session腳本監控

session腳本監控

原创 Linux操作系统 作者:aishu521 时间:2012-06-28 08:33:12 0 删除 编辑

oracle@tt> crontab -l

*/10 * * * * sh /exp/sys/session.sh

oracle@ZFKSFCDB01:/exp/sys> ls se*
session  session2  session_2  session_22  session27  session_27  session277  session7  session_7  session_77  session.sh  session.sql

oracle@ZFKSFCDB01:/exp/sys> cat  session.sh
rm /exp/sys/session.sql
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=fksfcdb1
export ORACLE_HOME=$ORACLE_BASE/oracle/product/10.2.0/db_1
export PATH=.:$ORACLE_HOME/bin:$PATH:.
/u01/app/oracle/oracle/product/10.2.0/db_1/bin/sqlplus / as sysdba << eof
declare n number ;
begin
for h in (select s.PROGRAM,s.TERMINAL,s.SCHEMANAME,s.STATUS,p.spid,s.logon_time
                 from V\$session s ,v\$process p
                      WHERE s.TYPE NOT in ('BACKGROUND') and p.addr like s.paddr)
loop
insert into check_session@check_link(host,PROGRAM,TERMINAL,SCHEMANAME,STATUS,spid,logon_time,RECORD_DATE)
values ('10.182.15.30',h.PROGRAM,h.TERMINAL,h.SCHEMANAME,h.STATUS,h.spid,h.logon_time,sysdate);
end loop ;
select  count(1) into n from v\$session where type not in ('BACKGROUND');
insert into session_all@check_link
(host,session_num,record_date)
values ('10.182.15.30',n,sysdate);
end;
/
commit;
exit;
eof
ps -ef |grep oracle |grep LOCAL > /exp/sys/session
awk '{print $2}' /exp/sys/session > /exp/sys/session2
awk '{print $7}' /exp/sys/session > /exp/sys/session7
cat /exp/sys/session2|sed s/^/,\'\/g>/exp/sys/session_2
cat /exp/sys/session7|sed s/^/,\'\/g>/exp/sys/session_7
cat /exp/sys/session_2|sed s/$/\'\/g>/exp/sys/session_22
cat /exp/sys/session_7|sed s/$/\'\/g>/exp/sys/session_77
cat /exp/sys/session2|sed s/^/insert\ into\ check_temp\ values\(\'10\.182\.15\.30\',\'/g>/exp/sys/session_27
cat /exp/sys/session_27|sed s/$/\'\/g>/exp/sys/session27
paste /exp/sys/session27 /exp/sys/session_77 >/exp/sys/session277
cat /exp/sys/session277|sed s/$/\,sysdate\)\;/g >>/exp/sys/session.sql
echo 'exit' >>/exp/sys/session.sql
export ORACLE_HOME="/u01/app/oracle/oracle/product/10.2.0/db_1/"
$ORACLE_HOME/bin/sqlplus oscheck/checkdb@test @/exp/sys/session.sql

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15187685/viewspace-733984/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-05-26

  • 博文量
    139
  • 访问量
    677659