v-list-web-domain-errorlog 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # info: list web domain error log
  3. # options: USER DOMAIN [LINES] [FORMAT]
  4. #
  5. # The function of obtaining raw error web domain logs.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. ttl=${3-70}
  13. format=${4-shell}
  14. # Includes
  15. source $VESTA/func/main.sh
  16. source $VESTA/conf/vesta.conf
  17. # Json function
  18. json_list_log() {
  19. i=1
  20. echo '['
  21. for str in $lines; do
  22. str=$(echo "$str" |sed -e 's/"/\\"/g')
  23. if [ "$i" -lt "$counter" ]; then
  24. echo -e "\t\"$str\","
  25. else
  26. echo -e "\t\"$str\""
  27. fi
  28. (( ++i))
  29. done
  30. echo "]"
  31. }
  32. # Shell function
  33. shell_list_log() {
  34. echo "$lines"
  35. }
  36. #----------------------------------------------------------#
  37. # Verifications #
  38. #----------------------------------------------------------#
  39. check_args '2' "$#" 'USER DOMAIN [LINES] [FORMAT]'
  40. validate_format 'user' 'domain' 'ttl'
  41. is_object_valid 'user' 'USER' "$user"
  42. is_object_valid 'web' 'DOMAIN' "$domain"
  43. #----------------------------------------------------------#
  44. # Action #
  45. #----------------------------------------------------------#
  46. # Check number of output lines
  47. if [ "$ttl" -gt '3000' ]; then
  48. read_cmd="cat"
  49. else
  50. read_cmd="tail -n $ttl"
  51. fi
  52. lines=$($read_cmd /var/log/$WEB_SYSTEM/domains/$domain.error.log)
  53. counter=$(echo "$lines" |wc -l)
  54. IFS=$'\n'
  55. # Listing logs
  56. case $format in
  57. json) json_list_log ;;
  58. plain) shell_list_log ;;
  59. shell) shell_list_log ;;
  60. esac
  61. #----------------------------------------------------------#
  62. # Vesta #
  63. #----------------------------------------------------------#
  64. exit