杀mysql sleep进程的shell

Standard
#!/bin/sh
while :
 
do
  n=`/usr/bin/mysqladmin processlist | grep -i sleep | wc -l`
  date=`date +%Y%m%d\[%H:%M:%S]`
  echo $n
 
  if [ "$n" -gt 10 ]
  then
    for i in `/usr/bin/mysqladmin processlist | grep -i sleep | awk '{print $2}'`
    do
      /usr/bin/mysqladmin kill $i
    done
    echo "sleep is too many i killed it" >> /tmp/sleep.log
    echo "$date : $n" >> /tmp/sleep.log
  fi
sleep 5
done

3 thoughts on “杀mysql sleep进程的shell

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.