v_list_database_server 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # info: list database server
  3. # options: type host [format]
  4. #
  5. # The function for obtaining database server parameters.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. type=$1
  11. host=$2
  12. format=${3-shell}
  13. # Includes
  14. source $VESTA/func/shared.sh
  15. # Json function
  16. json_list_dbhost() {
  17. i=1
  18. fields_count=$(echo "$fields" | wc -w)
  19. line=$(grep "HOST='$host'" $conf)
  20. echo '{'
  21. eval $line
  22. for field in $fields; do
  23. eval value=$field
  24. if [ "$i" -eq 1 ]; then
  25. echo -e "\t\"$value\": {"
  26. else
  27. if [ "$fields_count" -eq "$i" ]; then
  28. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  29. else
  30. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  31. fi
  32. fi
  33. (( ++i))
  34. done
  35. if [ -n "$value" ]; then
  36. echo -e "\t}"
  37. fi
  38. echo -e "}"
  39. }
  40. # Shell function
  41. shell_list_dbhost() {
  42. line=$(grep "HOST='$host'" $conf)
  43. eval $line
  44. for field in $fields; do
  45. eval key="$field"
  46. echo "${field//$/}: $key"
  47. done
  48. }
  49. #----------------------------------------------------------#
  50. # Verifications #
  51. #----------------------------------------------------------#
  52. check_args '2' "$#" 'type host [format]'
  53. validate_format 'host'
  54. is_object_valid "../../conf/$type" 'HOST' "$host"
  55. #----------------------------------------------------------#
  56. # Action #
  57. #----------------------------------------------------------#
  58. # Defining fileds to select
  59. conf=$VESTA/conf/$type.conf
  60. fields='$HOST $PORT $CHARSETS $MAX_DB $U_SYS_USERS $U_DB_BASES $TPL $SUSPENDED'
  61. fields="$fields \$TIME \$DATE"
  62. # Listing database
  63. case $format in
  64. json) json_list_dbhost ;;
  65. plain) nohead=1; shell_list_dbhost ;;
  66. shell) shell_list_dbhost | column -t;;
  67. *) check_args '2' '0' 'type host [format]'
  68. esac
  69. #----------------------------------------------------------#
  70. # Vesta #
  71. #----------------------------------------------------------#
  72. exit