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
推荐阅读
- Linux下面如何查看tomcat已经使用多少线程
- Beego打包部署到Linux
- 编写字典程序
- Linux|109 个实用 shell 脚本
- linux定时任务contab
- 怎么将桌面上的CAD图纸添加到软件中进行BMP格式转换()
- 芯灵思SinlinxA33开发板Linux内核定时器编程
- day16-Linux|day16-Linux 软件管理
- 如何在阿里云linux上部署java项目
- 2147483647与int型