杀掉mysql sleep进程的shell

2019年6月28日

#!/bin/bash

#while [ "2" -gt "1" ]
#do

         log_command=`mysqladmin processlist | grep -i sleep | wc -l`
         date=`date +%Y%m%d[%H:%M:%S]`
         #echo $log_command

         if [ "$log_command" -gt 250 ]
         then
             for i in `mysqladmin processlist | grep -i sleep | awk '{print $2}'`
             do
                   mysqladmin kill $i
             done

             echo "$date : $log_command, sleep is too many i killed it" >> /data/killsleep/sleep.log
         else
             echo "$date : $log_command, not need to kill" >> /data/killsleep/sleep.log
         fi

# sleep 180
#done

注意mysqladmin执行的用户,直接在命令行执行mysqladmin processlist | grep -i sleep | wc -l,

************************************************************************************

#!/bin/sh
PATH=$PATH:/usr/bin/
echo "show processlist" | mysql | grep Sleep | awk '{ if( $6> 60 ) print ("kill", $1, ";")}' | mysql

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注