From 852f631292c8fdd91f8f498e692ffde56d06ad40 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Fri, 29 Mar 2013 18:18:33 +0200 Subject: [PATCH] update ip counters --- bin/v-update-sys-ip-counters | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 bin/v-update-sys-ip-counters diff --git a/bin/v-update-sys-ip-counters b/bin/v-update-sys-ip-counters new file mode 100755 index 00000000..fdf05e0f --- /dev/null +++ b/bin/v-update-sys-ip-counters @@ -0,0 +1,65 @@ +#!/bin/bash +# info: update IP usage counters +# options: IP +# +# Function updates usage U_WEB_ADOMAINS and U_SYS_USERS counters. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +ip=$1 + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh +source $VESTA/func/ip.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '0' "$#" 'IP' +if [ ! -z "$ip" ]; then + validate_format 'ip' + is_ip_valid +fi + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Creating user_list +if [ -z "$ip" ]; then + ip_list=$(ls $VESTA/data/ips) +else + ip_list="$ip" +fi + +# Updating user stats +for ip in $ip_list; do + + # Calculate usage + ip_usage=$(grep -H $ip $VESTA/data/users/*/web.conf) + web_domains=$(echo "$ip_usage"| wc -l) + sys_users=$(echo "$ip_usage" | cut -f7 -d/ | sort -u |\ + tr '\n' ',' | sed -e "s/,$//g") + + # Update counters + update_ip_value '$U_WEB_DOMAINS' "$web_domains" + update_ip_value '$U_SYS_USERS' "$sys_users" +done + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_event "$OK" "$EVENT" + +exit