How to kill user session through database and Unix command


How to kill user session through database and Unix command

select
/*
   substr(a.spid,1,9) pid,
   substr(b.sid,1,5) sid,
   substr(b.serial#,1,5) ser#
*/
'alter system kill session ' || '''' || b.SID || ',' || b.serial# || ''' immediate;',
'!kill -9 ' || a.spid
from
   v$session b,
   v$process a
where
b.paddr = a.addr
--and type='USER'
--and b.username='BGGT'
--and b.LOGON_TIME < '12-FEB-08'
--and sid=47
order by spid;


This is and outuput example.

alter system kill session '82,15519' immediate;    !kill -9 1076
alter system kill session '170,1' immediate;    !kill -9 11990
alter system kill session '169,1' immediate;    !kill -9 11994
alter system kill session '168,1' immediate;    !kill -9 12000
alter system kill session '167,1' immediate;    !kill -9 12004
alter system kill session '166,1' immediate;    !kill -9 12009
alter system kill session '165,1' immediate;    !kill -9 12011
alter system kill session '164,1' immediate;    !kill -9 12013
alter system kill session '163,1' immediate;    !kill -9 12015
alter system kill session '162,1' immediate;    !kill -9 12017
alter system kill session '161,1' immediate;    !kill -9 12019
alter system kill session '160,1' immediate;    !kill -9 12021
alter system kill session '159,1' immediate;    !kill -9 12023
alter system kill session '158,1' immediate;    !kill -9 12027
alter system kill session '154,1' immediate;    !kill -9 12116
alter system kill session '153,1' immediate;    !kill -9 12120
alter system kill session '149,1' immediate;    !kill -9 12142
alter system kill session '156,8' immediate;    !kill -9 12843
alter system kill session '112,5999' immediate;    !kill -9 16879
alter system kill session '91,10427' immediate;    !kill -9 16885
alter system kill session '89,16256' immediate;    !kill -9 17338
alter system kill session '132,28' immediate;    !kill -9 18541
alter system kill session '101,9751' immediate;    !kill -9 19709

Comments