v-update-web-domains-traff 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. # Includes
  12. source $VESTA/conf/vesta.conf
  13. source $VESTA/func/main.sh
  14. source $VESTA/func/domain.sh
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. check_args '1' "$#" 'user'
  19. validate_format 'user'
  20. is_system_enabled "$WEB_SYSTEM"
  21. is_object_valid 'user' 'USER' "$user" "$user"
  22. is_object_unsuspended 'user' 'USER' "$user"
  23. #----------------------------------------------------------#
  24. # Action #
  25. #----------------------------------------------------------#
  26. for domain in $(search_objects 'web' 'SUSPENDED' "no" 'DOMAIN'); do
  27. log_file="/var/log/httpd/domains/$domain.bytes"
  28. bytes=0
  29. # Parsing log
  30. while read line; do
  31. if [[ '-' != "$line" ]] && [[ 0 -lt "$line" ]]; then
  32. bytes=$(($bytes + $line))
  33. fi
  34. done < $log_file
  35. # Converting to Mb
  36. mb=$(echo "$bytes / 1024 / 1024"|bc)
  37. # Nulling log
  38. echo > $log_file
  39. get_domain_values 'web'
  40. bandwidth=$((U_BANDWIDTH + mb))
  41. # Updating bandwidth value in config
  42. update_object_value 'web' 'DOMAIN' "$domain" '$U_BANDWIDTH' "$bandwidth"
  43. done
  44. #----------------------------------------------------------#
  45. # Vesta #
  46. #----------------------------------------------------------#
  47. # Recalculating user bandwidth
  48. recalc_user_bandwidth_usage
  49. # No Logging
  50. #log_event "$OK" "$EVENT"
  51. exit