定時殺死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
相關文章
相關標籤/搜索