v-list-backup-ftp-host 2.1 KB

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