-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnn_storage_quota
More file actions
executable file
·92 lines (81 loc) · 2.83 KB
/
nn_storage_quota
File metadata and controls
executable file
·92 lines (81 loc) · 2.83 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# nn_storage_quota
# matt.pestle@nesi.org.nz
# Mar 2025
#
# script to mimic the old nn_storage_quota, but use
# only the df command in real time. Weka does not enforce limits
# on inodes, so we are abandoning the reporting of inode usage.
#
# df is intercepted by weka and reports disk usage and capacity
# relative to the soft limit of any quota on the directory.
# (We have specifically requested this change of weka from the default
# which calculcates relatives to the hard limit).
# df also runs much more efficiently than querying weka, which also
# requires authentication to the weka system, which normal users
# cannot do.
#
# No arguments call is to report on the calling user's projects
# and $HOME directory.
# We report on project data, then nobackup data, then the user's
# home directory.
#
# Note that if anything is over the soft quota, df reports this
# as 100%, and usage as the soft quota - which is inaccurate
# in terms of disk usage (they will be using more than that),
# but sufficient for these purposes. For exact usage, you have
# to use "du", or authenticate to weka and query the weka
# system for usage. (see nn_storage_quotaw)
((bs=1024*1024*1024)) # We will work in GiB
((cvt=1))
NESI_HOME=/home
# Assumes/hardcodes /nesi/project and /nesi/nobackup as basedirs
# for project and scratch
function print_usage() {
echo "Usage: $0 [-h] [-p <project>] [-u <user>]"
echo
echo " -h, --help this help message"
echo " -p, --project <project> Show quotas for a named project"
echo " -u, --user <user> Show quotas for a named user"
echo "With no args, all the calling user's projects and \$HOME will be reported"
}
# Default call is for the calling user's information
((DO_HOME=1))
U=$(id -un)
GROUP_LIST=$(id -Gn)
(($#>0)) && case "$1" in
-h|--help|-help)
print_usage "help message"
exit 0
;;
-p|--project)
((DO_HOME=0))
GROUP_LIST=$2
;;
-u|--user)
U=$(id -un $2) || exit 1
GROUP_LIST=$(id -Gn $2)
;;
*)
print_usage "help message"
exit 0
;;
esac
HEADER="Quota_Location AvailableGiB UsedGiB Use%"
format_string="%-34.34s%18.18s%18.18s%5.5s\n"
echo "$HEADER" | awk -v format_string="$format_string" '{printf(format_string,$1,$2,$3,$4)}'
format_string="%-34.34s%18.0f%18.0f%5.0f\n"
for d in project nobackup
do
for g in $GROUP_LIST
do
[[ -d "/nesi/$d/$g" ]] && {
RPT=$(df --block-size=$bs "/nesi/$d/$g" --output=size,used,pcent | tail -1)
echo ${d}_${g} "$RPT" | awk -v format_string="$format_string" '{printf(format_string,$1,$2,$3,$4)}'
}
done
done
((DO_HOME)) || exit 0 # Done, unless we're doing somebody's $HOME
[[ -d "$NESI_HOME/$U" ]] || exit 0 # No $HOME, quit
RPT=$(df --block-size=$bs "$NESI_HOME/$U" --output=size,used,pcent | tail -1)
echo home_$U "$RPT" | awk -v format_string="$format_string" '{printf(format_string,$1,$2,$3,$4)}'