v-list-sys-ip 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. # Includes
  14. source $VESTA/func/main.sh
  15. source $VESTA/func/ip.sh
  16. # Json function
  17. json_list_ip() {
  18. i=1
  19. fileds_count=$(echo "$fields" | wc -w)
  20. ip_data=$(cat $VESTA/data/ips/$IP)
  21. echo '{'
  22. eval $ip_data
  23. for field in $fields; do
  24. eval value=$field
  25. if [ $i -eq 1 ]; then
  26. echo -e "\t\"$value\": {"
  27. else
  28. if [ $fileds_count -eq $i ]; then
  29. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  30. else
  31. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  32. fi
  33. fi
  34. (( ++i))
  35. done
  36. if [ -n "$value" ]; then
  37. echo -e ' }'
  38. fi
  39. echo -e '}'
  40. }
  41. # Shell function
  42. shell_list_ip() {
  43. line=$(cat $VESTA/data/ips/$IP)
  44. eval $line
  45. for field in $fields; do
  46. eval key="$field"
  47. if [ -z "$key" ]; then
  48. key='NULL'
  49. fi
  50. echo "${field//$/}: $key "
  51. done
  52. }
  53. #----------------------------------------------------------#
  54. # Verifications #
  55. #----------------------------------------------------------#
  56. # Checking args
  57. check_args '1' "$#" 'ip [format]'
  58. validate_format 'ip'
  59. is_ip_valid
  60. #----------------------------------------------------------#
  61. # Action #
  62. #----------------------------------------------------------#
  63. conf=$VESTA/data/ips/$IP
  64. # Defining fileds to select
  65. fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE
  66. $NETMASK $TIME $DATE'
  67. # Listing ip
  68. case $format in
  69. json) json_list_ip ;;
  70. plain) shell_list_ip ;;
  71. shell) shell_list_ip | column -t ;;
  72. *) check_args '1' '0' 'ip [format]'
  73. esac
  74. #----------------------------------------------------------#
  75. # Vesta #
  76. #----------------------------------------------------------#
  77. exit