v-list-sys-mysql-config 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # info: list mysql config parameters
  3. # options: [FORMAT]
  4. #
  5. # The function for obtaining the list of mysql config parameters.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. source $VESTA/conf/vesta.conf
  14. # JSON list function
  15. json_list() {
  16. eval $(echo "$config"|egrep "$keys"|\
  17. sed -e "s/[ ]*=/=/" -e "s/=[ ]*/=\'/" -e "s/$/'/")
  18. echo '{
  19. "CONFIG": {
  20. "max_user_connections": "'$max_user_connections'",
  21. "max_connections": "'$max_connections'",
  22. "wait_timeout": "'$wait_timeout'",
  23. "interactive_timeout": "'$interactive_timeout'",
  24. "max_allowed_packet": "'$max_allowed_packet'",
  25. "config_path": "'$config_path'"
  26. }
  27. }'
  28. }
  29. # SHELL list function
  30. shell_list() {
  31. echo "$config" |egrep "$keys" |tr '=' ' '
  32. echo "config_path $config_path"
  33. }
  34. # PLAIN list function
  35. plain_list() {
  36. echo "$config" |egrep "$keys" |tr '=' ' '
  37. echo "config_path $config_path"
  38. }
  39. # CSV list function
  40. csv_list() {
  41. echo "$keys" |sed "s/|/,/g"
  42. echo "$config" |egrep "$keys" |tr '=' ' ' |awk '{print $2}' |tr '\n' ','
  43. echo
  44. }
  45. #----------------------------------------------------------#
  46. # Action #
  47. #----------------------------------------------------------#
  48. # Defining config path
  49. config_path=$(find /etc/my* -name my.cnf)
  50. # Defining keys
  51. keys="max_user_connections|max_connections|wait_timeout|interactive_timeout"
  52. keys="${keys}|max_allowed_packet"
  53. # Reading config
  54. config=$(cat $config_path|grep -v "^;")
  55. # Listing data
  56. case $format in
  57. json) json_list ;;
  58. plain) plain_list ;;
  59. csv) csv_list ;;
  60. shell) shell_list |column -t;;
  61. esac
  62. #----------------------------------------------------------#
  63. # Vesta #
  64. #----------------------------------------------------------#
  65. exit