v_list_sys_ip 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. # info: list system ip
  3. # options: ip [format]
  4. #
  5. # The function for getting the list of system ip parameters.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. ip=$1
  11. IP=$ip
  12. format=${2-shell}
  13. # Importing variables
  14. source $VESTA/conf/vars.conf
  15. source $V_FUNC/shared.func
  16. source $V_FUNC/ip.func
  17. # Json function
  18. json_list_ip() {
  19. i=1
  20. fileds_count=$(echo "$fields" | wc -w)
  21. ip_data=$(cat $V_IPS/$IP)
  22. # Print top bracket
  23. echo '{'
  24. # Assign key=value
  25. eval $ip_data
  26. for field in $fields; do
  27. eval value=$field
  28. # Checking first field
  29. if [ $i -eq 1 ]; then
  30. echo -e "\t\"$value\": {"
  31. else
  32. if [ $fileds_count -eq $i ]; then
  33. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  34. else
  35. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  36. fi
  37. fi
  38. (( ++i))
  39. done
  40. # If there was any output
  41. if [ -n "$value" ]; then
  42. echo -e ' }'
  43. fi
  44. # Printing bottom json bracket
  45. echo -e '}'
  46. }
  47. # Shell function
  48. shell_list_ip() {
  49. line=$(cat $V_IPS/$IP)
  50. # Assing key=value
  51. eval $line
  52. # Print result line
  53. for field in $fields; do
  54. eval key="$field"
  55. echo "${field//$/}: $key "
  56. done
  57. }
  58. #----------------------------------------------------------#
  59. # Verifications #
  60. #----------------------------------------------------------#
  61. # Checking args
  62. check_args '1' "$#" 'ip [format]'
  63. # Checking argument format
  64. format_validation 'ip'
  65. # Checking ip
  66. is_sys_ip_valid
  67. #----------------------------------------------------------#
  68. # Action #
  69. #----------------------------------------------------------#
  70. conf=$V_IPS/$IP
  71. # Defining fileds to select
  72. fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS
  73. $INTERFACE $NETMASK $DATE'
  74. # Listing ip
  75. case $format in
  76. json) json_list_ip ;;
  77. plain) shell_list_ip ;;
  78. shell) shell_list_ip | column -t ;;
  79. *) check_args '1' '0' 'ip [format]'
  80. esac
  81. #----------------------------------------------------------#
  82. # Vesta #
  83. #----------------------------------------------------------#
  84. exit