需求:IEE数据库临时需要添加一个监控,将command为sleep,time>1800,info为null的进程自动杀掉。
1.杀进程脚本ieekill.sh内容如下
#!/bin/bash
#Usage: IEE kill process whose time more than 1800s..
#ex: sh ieekill.sh >> /tmp/ieekill.log
#Author: Alfred Zhao
#Version: 1.0.0
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
date
if [ -f /tmp/kill_iee_id.txt ]; then
echo "rm -rf /tmp/kill_iee_id.txt"
rm -rf /tmp/kill_iee_id.txt
else
echo "go on"
fi
mysql-ib <<EOF
SELECT CONCAT('KILL ',ID,';') FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='root' AND COMMAND='Sleep' AND INFO is null AND TIME > 1800 INTO OUTFILE '/tmp/kill_iee_id.txt';
source /tmp/kill_iee_id.txt
EOF
2.定时调用脚本定时配置
crontab -e 添加下面的配置,每小时执行1次杀进程脚本。
0 * * * * sh /tmp/ieekill.sh >> /tmp/ieekill.log