-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgdata-info
executable file
·61 lines (53 loc) · 1.45 KB
/
gdata-info
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
#!/bin/bash
set -e
print_help() {
cat <<EOF
Print information about gdata mounts
Options:
-P PROJ Mount point of project PROJ
-m MOUNT Projects stored on MOUNT
-M List all available MOUNTs
EOF
}
# A list of (mount point, project) from 'mount'
mount_info=$(mount | sed -E -n 's|.*:/(\S+) on /g/data/(\S+) type lustre.*|\1 \2|p' | sort)
optspec="hP:m:M"
while getopts "$optspec" optchar; do
case "${optchar}" in
h)
print_help
exit 2
;;
P)
# Find all occurrences of project in mount_info
PROJ="${OPTARG}"
grep "\s$PROJ\$" <<< "$mount_info" | cut -f 1 -d ' '
exit
;;
m)
# Find all occurrences of mount in mount info
MOUNT="${OPTARG}"
avail=$(grep "^$MOUNT\s" <<< "$mount_info" | cut -f 2 -d ' ')
# The projects current user is a member of
member=$(id -Gn | tr ' ' '\n')
# Find all projects listed twice (ie. both a member of and in the current mount search)
both=$(cat <<EOF
$avail
$member
EOF
)
sort <<< "$both" | uniq -c | sed -n 's/^\s*2\s\(\S\+\)$/\1/p'
exit
;;
M)
# List of unique mount points
cut -f 1 -d ' ' <<< "$mount_info" | sort -u
exit
;;
*)
print_help
exit 2
;;
esac
done
echo "$mount_info"