You are on page 1of 1

SHELL Script:

============
[oracle@rdc1pldcora101:ldcbpmpr]$cat kill_inactive_ldcbpmpr.sh
#!/bin/bash
export ORACLE_SID=ldcbpmpr
export ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
sqlplus "/as sysdba" <<EOF
select name,open_mode,log_mode,database_role from v\$database;
set head off;
select 'alter system kill session '''||sid||','||serial#||''' immediate;' from V\
$SESSION where SECONDS_IN_WAIT>600 and type='USER' and username is not null and
username not in ('TIVOLI','DBSNMP','PUBLIC','SYS','SYSTEM') and status='INACTIVE';
spool /home/oracle/scripts/kill_inactive_session.sql
/
spool off;
set echo on;
spool /home/oracle/scripts/kill_inactive_ldcbpmpr.log
@/home/oracle/scripts/kill_inactive_session.sql
spool off;
exit
EOF
---------------
Crontab setting:
---------------
0 * * * * /home/oracle/scripts/kill_inactive_ldcbpmpr.sh >
/home/oracle/scripts/cron_kill_inactive_ldcbpmpr.log

=======================
The above 2 generates 3 files
1. kill_inactive_session.sql : whick contains all dynamic alter system kill
session commands to kill all selected sessions.
2.kill_inactive_ldcbpmpr.log : Log file of command kill_inactive_session.sql
3. cron_kill_inactive_ldcbpmpr.log : Log file of kill_inactive_ldcbpmpr.sh

You might also like