Skip to content

Instantly share code, notes, and snippets.

@akkunchoi
Created January 24, 2011 11:34
Show Gist options
  • Save akkunchoi/793114 to your computer and use it in GitHub Desktop.
Save akkunchoi/793114 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'time'
list = `mysql -uroot -e "show full processlist"`
print list
list.split("\n").each { |line|
d = line.split(" ", 8)
if d[4] == "Query" and d[5].to_i >= 60
print "kill #{d[0]}\n"
`mysql -uroot -e "kill #{d[0]}"`
File.open("killed.log", 'a') do |f|
f.write(Time.now.to_s + " " + line + "\n")
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment