-
Notifications
You must be signed in to change notification settings - Fork 1
/
aquota
executable file
·86 lines (68 loc) · 2.19 KB
/
aquota
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
#!/bin/bash
# vim: set et ai sw=3 ts=3 :
# Display a users ACFS quota and disk usage.
# -- 2024/08 uccafot
set -o errexit \
-o nounset \
-o pipefail
usage () {
local rc="$1"
[[ -z "$rc" ]] && rc=1
cat <<EOF
Usage: aquota [ <username> ]
Display the user's ACFS quota and disk usage.
Without username, defaults to the current user.
EOF
exit "$rc"
}
error () {
local msg="$1"
echo "ERROR: ${msg}" >&2
exit 1
}
_timeout_guard () {
timeout -k 3 5 "$@"
rc=$?
[[ "$rc" -eq 124 ]] && error "Command timed out. Server unavailable?"
return "$rc"
}
kiB_to_human () {
local size="$1"
# RHEL7 numfmt doesn't support precision control :(
numfmt --from=iec-i --to=iec-i --suffix B "${size}KiB"
}
# GPFS reports quota and usage as the actually allocated disk space,
# i.e. including the replication factor (2, for us). For the whole
# saga, see https://github.com/UCL-ARC/Book-of-RDP/issues/96
repfac=2
# ACFS mount point
ACFSdir='/acfs/users'
while getopts ':h' opt; do
case "$opt" in
h) usage 0 ;;
*) error "invalid option: $OPTARG" ;;
esac
done
shift $((OPTIND-1))
username="${1:-"${USER:-}"}"
[[ -n "$username" ]] \
|| error "cannot determine username to use: no argument provided and USER variable not set."
userdir="${ACFSdir}/${username}"
_timeout_guard mountpoint -q "${ACFSdir}" \
|| error "ACFS is not mounted."
_timeout_guard test -d "${userdir}" \
|| error "ACFS directory '${userdir}' doesn't exist."
# Note that:
# - this is intended to point at an NFS mount of a GPFS system
# - running df against one of those gives the *fileset quota* which we are using per-user
# - so this gives us the user's quota on ACFS, *not* the total available storage on the ACFS
# - ACFS has actual user (and group) quotas and we are not using them
# - yes, this is, overall, a little weird
df_output="$( _timeout_guard df -k --output='size,used,pcent' "${userdir}" | tail -n 1 )"
read -r bquota bused bpct <<< "${df_output}"
bquota="$(kiB_to_human "$(( bquota / repfac ))")"
bused="$(kiB_to_human "$(( bused / repfac ))")"
printf "%-20s %7s %7s %6s\n" \
"Path" "Used" "Quota" "%Used"
printf "%-20s %7s %7s %6s\n" \
"$userdir" "$bused" "$bquota" "$bpct"