v_update_web_domains_traff 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # info: update domains bandwidth usage
  3. # options: user
  4. #
  5. # The function recalculates bandwidth usage for all user webdomains.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. # Importing variables
  12. source $VESTA/conf/vars.conf
  13. source $V_CONF/vesta.conf
  14. source $V_FUNC/shared.func
  15. source $V_FUNC/domain.func
  16. #----------------------------------------------------------#
  17. # Verifications #
  18. #----------------------------------------------------------#
  19. # Checking arg number
  20. check_args '1' "$#" 'user'
  21. # Checking argument format
  22. format_validation 'user'
  23. # Checking web system is enabled
  24. is_system_enabled 'web'
  25. # Checking user
  26. is_user_valid "$user"
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Defining config
  31. conf="$V_USERS/$user/web.conf"
  32. # Defining fileds to select
  33. field='$DOMAIN'
  34. # Defining search string
  35. search_string="SUSPEND='no'"
  36. # Parsing unsuspeneded domains
  37. domains=$(dom_clear_search)
  38. # Starting suspend loop
  39. for domain in $domains; do
  40. # Defining log file
  41. log_file="/var/log/httpd/domains/$domain.bytes"
  42. # Defining bytes
  43. bytes=0
  44. # Parsing log
  45. while read line; do
  46. if [[ '-' != "$line" ]] && [[ 0 -lt "$line" ]]; then
  47. bytes=$(($bytes + $line))
  48. fi
  49. done < $log_file
  50. # Converting to Mb
  51. mb=$(echo "$bytes / 1024 / 1024"|bc)
  52. # Nulling log
  53. echo > $log_file
  54. # Parsing old value
  55. old_val=$(get_web_domain_value '$U_BANDWIDTH')
  56. # Defining new value
  57. bandwidth=$((old_val + mb))
  58. # Updating bandwidth value in config
  59. update_web_domain_value '$U_BANDWIDTH' "$bandwidth"
  60. done
  61. #----------------------------------------------------------#
  62. # Vesta #
  63. #----------------------------------------------------------#
  64. # Recalculating user bandwidth
  65. traff_size=$(get_usr_traff)
  66. update_user_value "$user" '$U_BANDWIDTH' "$traff_size"
  67. # Logging
  68. log_event 'system' "$V_EVENT"
  69. exit