Skip to content

Commit 852f631

Browse files
committed
update ip counters
1 parent 65db511 commit 852f631

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

bin/v-update-sys-ip-counters

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# info: update IP usage counters
3+
# options: IP
4+
#
5+
# Function updates usage U_WEB_ADOMAINS and U_SYS_USERS counters.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
ip=$1
14+
15+
# Includes
16+
source $VESTA/conf/vesta.conf
17+
source $VESTA/func/main.sh
18+
source $VESTA/func/ip.sh
19+
20+
21+
#----------------------------------------------------------#
22+
# Verifications #
23+
#----------------------------------------------------------#
24+
25+
check_args '0' "$#" 'IP'
26+
if [ ! -z "$ip" ]; then
27+
validate_format 'ip'
28+
is_ip_valid
29+
fi
30+
31+
32+
#----------------------------------------------------------#
33+
# Action #
34+
#----------------------------------------------------------#
35+
36+
# Creating user_list
37+
if [ -z "$ip" ]; then
38+
ip_list=$(ls $VESTA/data/ips)
39+
else
40+
ip_list="$ip"
41+
fi
42+
43+
# Updating user stats
44+
for ip in $ip_list; do
45+
46+
# Calculate usage
47+
ip_usage=$(grep -H $ip $VESTA/data/users/*/web.conf)
48+
web_domains=$(echo "$ip_usage"| wc -l)
49+
sys_users=$(echo "$ip_usage" | cut -f7 -d/ | sort -u |\
50+
tr '\n' ',' | sed -e "s/,$//g")
51+
52+
# Update counters
53+
update_ip_value '$U_WEB_DOMAINS' "$web_domains"
54+
update_ip_value '$U_SYS_USERS' "$sys_users"
55+
done
56+
57+
58+
#----------------------------------------------------------#
59+
# Vesta #
60+
#----------------------------------------------------------#
61+
62+
# Logging
63+
log_event "$OK" "$EVENT"
64+
65+
exit

0 commit comments

Comments
 (0)