定时杀死mysql中sleep的进程

#!/bin/sh

date=`date +%Y%m%d\[%H:%M:%S]`

n=`mysqladmin -uroot -p** processlist | grep -i sleep | wc -l`

echo "sleep count:$n"

if [ "$n" -gt 10 ]; 
then
 for i in `mysqladmin -uroot -p** processlist | grep -i sleep | awk '$12>4000 {print $2}'`
 do
   mysqladmin -uroot -p** kill $i
 done

 echo "sleep is too many i killed it(time>4000)." >> /tmp/sleep.log
 echo "$date : $n" >> /tmp/sleep.log
 
fi

 

posted @ 2019-10-10 10:19  yshy  阅读(892)  评论(0编辑  收藏  举报