Skip to content

Instantly share code, notes, and snippets.

@hasantayyar
Created April 8, 2014 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hasantayyar/10115358 to your computer and use it in GitHub Desktop.
Save hasantayyar/10115358 to your computer and use it in GitHub Desktop.
kill slow processes
#!/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