Linux|Linux 添加 crontab 定时清理 Oracle 长时间 INACTIVE session

Linux 添加 crontab 定时清理 Oracle 长时间 INACTIVE session

if [ ! -d "${HOME}/cront/" ]; then mkdir ${HOME}/cront else echo "Do nothing" fi# ${HOME}/cront/ks.sql echo "set trimspool on spool ${HOME}/cront/kills.sh replace set pagesize 0 set heading off set linesize 32767 SELECT '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.sql echo "oradebug wakeup 2; exit; " > ${HOME}/cront/debug.sql# ${HOME}/cront/ks.sh echo '#!/bin/bash' > ${HOME}/cront/ks.sh echo '' > ${HOME}/cront/cron_kill.log echo '' > ${HOME}/cront/kill.sh echo '' > ${HOME}/cront/kills.sh echo "source ${HOME}/.bash_profile sqlplus / as sysdba @${HOME}/cront/ks.sql grep \"kill\" ${HOME}/cront/kills.sh > ${HOME}/cront/kill.sh echo -e >> ${HOME}/cront/cron_kill.log echo \"################# Started 'kill -9' commend at \`date +'%F %T %A'\` ##################\" > ${HOME}/cront/cron_kill.log echo -e >> ${HOME}/cront/cron_kill.log # Kill session ${HOME}/cront/kill.sh >> ${HOME}/cront/cron_kill.log# oradebug echo \"# oradebug , No Information Return\" >> ${HOME}/cront/cron_kill.log sqlplus / as sysdba @${HOME}/cront/debug.sql# Info echo -e >> ${HOME}/cront/cron_kill.log echo \"Warning: \`cat ${HOME}/cront/kill.sh | wc -l\` processes Killed. \" >> ${HOME}/cront/cron_kill.log echo -e >> ${HOME}/cront/cron_kill.log echo \"################Stoped at \`date +'%F %T'\` ################\" >> ${HOME}/cront/cron_kill.log " >> ${HOME}/cront/ks.sh# Grant execute permission chmod +x ${HOME}/cront/*# Add Crontd (crontab -l | grep -v "ks.sh") | crontab (crontab -l ; echo "*/30 * * * * /bin/bash ${HOME}/cront/ks.sh") | crontab

    推荐阅读