-
Notifications
You must be signed in to change notification settings - Fork 2
/
group-compare
executable file
·44 lines (37 loc) · 990 Bytes
/
group-compare
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
#!/bin/bash
# compare group member with MyGroups
# Ruoshi Sun
# 2020-10-26: use comm; add "Remove"
# 2020-01-24
GROUP="https://rci.hpc.virginia.edu/filesplus/group.txt"
TMP1=$(mktemp)
TMP2=$(mktemp)
for g in $@; do
echo ["$g"]
curl -s $GROUP | sed -n "s/^${g}:.*://p" | tr ',' '\n' >$TMP1
getent group $g| sed 's/^.*://' | tr ',' '\n' | sort >$TMP2
N1=$(wc -l <$TMP1)
N2=$(wc -l <$TMP2)
echo "group.txt ($N1):"
cat $TMP1 | tr '\n' ' '
echo
echo "rivanna ($N2):"
cat $TMP2 | tr '\n' ' '
echo
ADD=( $(comm -1 -3 $TMP2 $TMP1 ) )
REMOVE=( $(comm -1 -3 $TMP1 $TMP2 ) )
echo
if [[ ${#ADD[@]} -eq 0 && ${#REMOVE[@]} -eq 0 ]]; then
echo "Identical"
else
if [ ${#ADD[@]} -ne 0 ]; then
echo "Add (${#ADD[@]}):"
echo ${ADD[@]}
fi
if [ ${#REMOVE[@]} -ne 0 ]; then
echo "Remove (${#REMOVE[@]}):"
echo ${REMOVE[@]}
fi
fi
done
rm $TMP1 $TMP2