v_list_db_host 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/bash
  2. # info: listing data base servers
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. type=$1
  8. host=$2
  9. format=${3-shell}
  10. # Importing variables
  11. source $VESTA/conf/vars.conf
  12. source $V_FUNC/shared.func
  13. source $V_FUNC/db.func
  14. # Json function
  15. json_list_dbhost() {
  16. # Definigng variables
  17. i=1
  18. # Define words number
  19. fields_count=$(echo "$fields" | wc -w)
  20. # Reading file line by line
  21. line=$(grep "HOST='$host'" $conf)
  22. # Print top bracket
  23. echo '{'
  24. # Assign key=value
  25. eval $line
  26. # Starting output loop
  27. for field in $fields; do
  28. # Parsing key=value
  29. eval value=$field
  30. # Checking first field
  31. if [ "$i" -eq 1 ]; then
  32. echo -e "\t\"$value\": {"
  33. else
  34. if [ "$fields_count" -eq "$i" ]; then
  35. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  36. else
  37. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  38. fi
  39. fi
  40. (( ++i))
  41. done
  42. # If there was any output
  43. if [ -n "$value" ]; then
  44. echo -e "\t}"
  45. fi
  46. # Printing bottom json bracket
  47. echo -e "}"
  48. }
  49. # Shell function
  50. shell_list_dbhost() {
  51. # Reading file line by line
  52. line=$(grep "HOST='$host'" $conf)
  53. # Parsing key=value
  54. eval $line
  55. # Print result line
  56. for field in $fields; do
  57. eval key="$field"
  58. echo "${field//$/}: $key"
  59. done
  60. }
  61. #----------------------------------------------------------#
  62. # Verifications #
  63. #----------------------------------------------------------#
  64. # Checking args
  65. check_args '2' "$#" 'type host [format]'
  66. # Checking argument format
  67. format_validation 'host'
  68. # Checking db type
  69. is_type_valid 'db' "$type"
  70. # Checking db host
  71. is_db_host_valid
  72. #----------------------------------------------------------#
  73. # Action #
  74. #----------------------------------------------------------#
  75. # Defining config type
  76. conf=$V_DB/$type.conf
  77. # Defining fileds to select
  78. fields='$HOST $PORT $MAX_USERS $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE'
  79. # Listing database
  80. case $format in
  81. json) json_list_dbhost ;;
  82. plain) nohead=1; shell_list_dbhost ;;
  83. shell) shell_list_dbhost | column -t;;
  84. *) check_args '2' '0' 'type host [format]'
  85. esac
  86. #----------------------------------------------------------#
  87. # Vesta #
  88. #----------------------------------------------------------#
  89. exit