-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoc_storage-1
77 lines (66 loc) · 1.85 KB
/
oc_storage-1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# TODO: Error Checks
# Credentials file checker ---> Start
oc_credentials check
VALID=$(echo "$?")
if [ $VALID = "1" ]; then
tput setaf 1
echo "One error with your credentias has occurred, Please run oc_credentials to fix it!"
tput sgr0
exit 1
fi
CRED=~/.oC_credentials
# shellcheck source=~/.oC_credentials
. "$CRED"
# Credentials file checker <--- End
# Help ---> Start
display_help() {
echo "Usage: $0 [user]" >&2
echo
echo " -h, --help This help output "
echo
exit 1
}
case "$1" in
-h | -help | --help)
display_help
exit 0
;;
esac
# Help <--- End
OLDIFS=$IFS
IFS=$'\n'
# TODO: Optimize Query
DB_STORAGES="$(printf "select m.user_id, fc.size, s.id, fc.name from %smounts m, %sfilecache fc, %sstorages s where m.mount_point=concat('/', m.user_id, '/') and s.numeric_id=m.storage_id and fc.storage=m.storage_id and fc.path='files';" "$DB_PREFIX" "$DB_PREFIX" "$DB_PREFIX")"
RESULTS="$(mysql -N -u "$DB_USER" --password="$DB_PASSWORD" "$DB_NAME" -se "$DB_STORAGES")"
cnt=${#RESULTS[@]}
for (( i=0 ; i<cnt ; i++ ))
do
# X3=`echo "${RESULTS[$i]}" | awk -F$'\t' '{ print $3 }'`
# X4=`echo "${RESULTS[$i]}" | awk -F$'\t' '{ print $4 }'`
XUSER=`echo "${RESULTS[$i]}" | awk -F$'\t' '{ print $1 }'`
B=`echo "${RESULTS[$i]}" | awk -F$'\t' '{ print $2 }'`
if [ $B -lt 1024 ]; then
SIZE="${B} bytes"
else
KB=$(((B+512)/1024))
if [ $KB -lt 1024 ]; then
SIZE="${KB} kilobytes"
else
MB=$(((KB+512)/1024))
if [ $MB -lt 1024 ]; then
SIZE="${MB} megabytes"
else
GB=$(((MB+512)/1024))
if [ $GB -lt 1024 ]; then
SIZE="${GB} gigabytes"
else
SIZE="$(((GB+512)/1024)) terabytes"
fi
fi
fi
fi
printf "$XUSER -> $SIZE\n"
# printf "$XUSER -> $SIZE -> $X3 -> $X4\n"
done
IFS=$OLDIFS