kill_mysql_sleep_thread

jasperjohn發表於2014-11-03
#!/bin/bash
while [ "2" -gt "1" ]
          sleep_sum=`mysqladmin -uroot -ptonggangdasha processlist | grep -i sleep | wc -l`
          date=`date "+%F->%R"`
          #echo $sleep_sum
          if [ "$sleep_sum" -gt 250 ]
          then
              for i in `mysqladmin -uroot -ptonggangdasha processlist | grep -i sleep | awk '{print $2}'`
              do
                    `mysqladmin -uroot -ptonggangdasha kill $i`
              done
              echo "$date:$sleep_sum,sleep is too many i killed it" >> /opt/kill_sleep/sleep.log
          else
              echo "$date:$sleep_sum,not need to kill" >> /opt/kill_sleep/sleep.log
          fi
           sleep 180

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14661773/viewspace-1318787/,如需轉載,請註明出處,否則將追究法律責任。