v_list_sys_ip 2.3 KB

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