vesta/bin/v_upd_sys_user_disk
2011-06-14 00:22:25 +03:00

68 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# info: updating disk usage for user directories
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user="$1"
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'user'
# Checking argument format
format_validation 'user'
# Checking user
is_user_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Saving old IFS
OLDIFS=$IFS
IFS=$(echo -en "\n\b")
# Defining directory list
dir_list=$(ls $V_HOME/$user/ |grep -v '^domains$' | grep -v '^backup$' |\
grep -v '^conf$')
# Starting update disk loop
disk_usage='0'
for dir in $dir_list; do
dir_disk=$(du -shm "$V_HOME/$user/$dir"|cut -f 1 )
disk_usage=$((disk_usage + dir_disk))
done
# Restoring old IFS
IFS=$OLDIFS
# Updating disk value in config
update_user_value "$user" '$U_DIR_DISK' "$disk_usage"
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Recalculating user disk space
disk_size=$(get_usr_disk)
update_user_value "$user" '$U_DISK' "$disk_size"
# Logging
log_event 'system' "$V_EVENT"
exit $OK