Linux 增加 crontab 定时清理 Oracle 长时间 INACTIVE session
if [ ! -d "${HOME}/cront/" ];thenmkdir ${HOME}/crontelseecho "Do nothing"fi# ${HOME}/cront/ks.sqlecho "set trimspool onspool ${HOME}/cront/kills.sh replaceset pagesize 0set heading offset linesize 32767SELECT 'kill -9 ' || P.SPID FROM V\$PROCESS P WHERE P.ADDR IN (SELECT B.PADDR FROM V\$SESSION B WHERE B.TYPE = 'USER' AND B.STATUS = 'INACTIVE' AND B.LAST_CALL_ET > 3600);exit;spool off" > ${HOME}/cront/ks.sql# ${HOME}/cront/debug.sqlecho "oradebug wakeup 2;exit;" > ${HOME}/cront/debug.sql# ${HOME}/cront/ks.shecho '#!/bin/bash' > ${HOME}/cront/ks.shecho '' > ${HOME}/cront/cron_kill.logecho '' > ${HOME}/cront/kill.shecho '' > ${HOME}/cront/kills.shecho "source ${HOME}/.bash_profilesqlplus / as sysdba @${HOME}/cront/ks.sqlgrep \"kill\" ${HOME}/cront/kills.sh > ${HOME}/cront/kill.shecho -e >> ${HOME}/cront/cron_kill.logecho \"################# Started 'kill -9' commend at \`date +'%F %T %A'\` ##################\" > ${HOME}/cront/cron_kill.logecho -e >> ${HOME}/cront/cron_kill.log# Kill session${HOME}/cront/kill.sh >> ${HOME}/cront/cron_kill.log# oradebugecho \"# oradebug , No Information Return\" >> ${HOME}/cront/cron_kill.logsqlplus / as sysdba @${HOME}/cront/debug.sql# Infoecho -e >> ${HOME}/cront/cron_kill.logecho \"Warning: \`cat ${HOME}/cront/kill.sh | wc -l\` processes Killed. \" >> ${HOME}/cront/cron_kill.logecho -e >> ${HOME}/cront/cron_kill.log echo \"################ Stoped at \`date +'%F %T'\` ################\" >> ${HOME}/cront/cron_kill.log" >> ${HOME}/cront/ks.sh# Grant execute permissionchmod +x ${HOME}/cront/*# Add Crontd(crontab -l | grep -v "ks.sh") | crontab(crontab -l ; echo "*/30 * * * * /bin/bash ${HOME}/cront/ks.sh") | crontab