Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/local/bin/ruby
  2.  
  3. require 'mysql'
  4.  
  5. EXCLUDE_DATABASES = [
  6. 'information_schema',
  7. 'performance_schema',
  8. ]
  9.  
  10. host = ARGV[0]
  11. user = ARGV[1]
  12. password = ARGV[2]
  13.  
  14. begin
  15. db = Mysql.new(host, user, password)
  16. rescue Mysql::Error => e
  17. print 'NG ' + e.message
  18. exit 2
  19. end
  20.  
  21. errors = []
  22. db.query('SHOW DATABASES').each do |row_db|
  23. name_db = row_db[0]
  24. next if EXCLUDE_DATABASES.member?(name_db)
  25. db.query("USE `#{name_db}`")
  26. db.query('SHOW TABLES').each do |row_table|
  27. name_table = row_table[0]
  28. status = false
  29. db.query("CHECK TABLE `#{name_table}`").each do |row_check|
  30. if (row_check[2] == 'status') and (row_check[3] == 'OK')
  31. status = true
  32. break
  33. end
  34. end
  35. unless status
  36. errors.push("#{name_db}.#{name_table}")
  37. end
  38. end
  39. end
  40. db.close
  41.  
  42. if errors.empty?
  43. print 'OK'
  44. exit 0
  45. else
  46. print "NG #{errors.join(' ')}"
  47. exit 2
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement