Created
April 8, 2014 12:10
-
-
Save hasantayyar/10115358 to your computer and use it in GitHub Desktop.
kill slow processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
linecount=0 | |
processes=$(echo "show processlist" | mysql -uroot -proot) | |
oldIfs=$IFS | |
IFS=' | |
' | |
echo "Checking for slow MySQL queries..." | |
for line in $processes | |
do | |
if [ "$linecount" -gt 0 ] | |
then | |
pid=$(echo "$line" | cut -f1) | |
length=$(echo "$line" | cut -f6) | |
query=$(echo "$line" | cut -f8) | |
if [ "$length" -gt 60 ] | |
then | |
#echo "$pid = $length" | |
echo "pid=$pid - time:$length secs. - query=$query \n" | |
killoutput=$(echo "kill query $pid" | mysql -uroot -proot) | |
echo "Result of killing $pid: $killoutput\n\n" | |
fi | |
fi | |
linecount=`expr $linecount + 1` | |
done | |
IFS=$oldIfs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment