#!/bin/sh
mysql_pwd="root的密码"
mysqladmin_exec="/usr/local/bin/mysqladmin"
mysql_exec="/usr/local/bin/mysql"
"/tmp"
mysql_timeout_log="$mysql_timeout_dir/mysql_timeout.log"
mysql_kill_timeout_sh="$mysql_timeout_dir/mysql_kill_timeout.sh"
"$mysql_timeout_dir/mysql_kill_timeout.log"
$mysqladmin_exec -uroot -p"$mysql_pwd" processlist |
linuxjishu/13830.html target=_blank class=infotextkey>awk '{ print $12 , $2 ,$4}' | grep -v Time | grep -v '|' | sort -rn > $mysql_timeout_log
awk '{if($1>30 && $3!="root") print "'""$mysql_exec""' -e " "/"" "kill",$2 "/"" " -uroot " "-p""/"""'""$mysql_pwd""'""/"" ";" }' $mysql_timeout_log > $mysql_kill_timeout_sh
echo "check start ." >> $mysql_kill_timeout_log
echo `date` >> $mysql_kill_timeout_log
cat $mysql_kill_timeout_sh
然后chmod 0 mysqld_kill_sleep.sh,chmod u+rx mysqld_kill_sleep.sh,然后用root账户到cron里面运行即可,时间自己调整。
#!/bin/bash
mysql_pwd="密码"
mysql_exec="/usr/local/mysql/bin/mysql"
mysql_timeout_dir="/tmp"
mysql_kill_timeout_sh="$mysql_timeout_dir/mysql_kill_timeout.sh"
"$mysql_timeout_dir/mysql_kill_timeout.log"
$mysql_exec -uroot -p$mysql_pwd -e "show processlist" | grep -i "Locked" >> $mysql_kill_timeout_log
for line in `$mysql_kill_timeout_log | awk '{print $1}'`
do
echo "$mysql_exec -uroot -p$mysql_pwd -e /"kill $line/"" >> $mysql_kill_timeout_sh
done
cat $mysql_kill_timeout_sh