-
Notifications
You must be signed in to change notification settings - Fork 0
/
usrgrps
67 lines (58 loc) · 1.51 KB
/
usrgrps
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
#!/usr/bin/env bash
#
###############################################################################
# Environment
###############################################################################
# $_ME
#
# This program's basename.
_ME="$(basename "${0}")"
###############################################################################
# Help
###############################################################################
# _print_help()
#
# Usage:
# _print_help
#
# Print the program help information.
_print_help() {
cat <<HEREDOC
Program to output a machine's users and groups they belong to.
Usage:
${_ME} [OPTION]
Options:
-h --help Show this screen.
-s Only display information for standard users
-m Only display information for system users
no option prints information for all users
HEREDOC
}
_usage() {
echo "Usage: ${_ME} [OPTION]"
}
###############################################################################
# Main
###############################################################################
_main() {
if [[ -z "${1:-}" ]]
then
awk -F ":" '$3 >= 0 {system("groups " $1)}' /etc/passwd
else
if [[ "${1:-}" =~ ^-h|--help$ ]]
then
_print_help
elif [[ "${1:-}" =~ ^-s$ ]]
then
awk -F ":" '$3 >= 1000 {system("groups " $1)}' /etc/passwd
elif [[ "${1:-}" =~ ^-m$ ]]
then
awk -F ":" '$3 < 1000 {system("groups " $1)}' /etc/passwd
else
echo "Invalid option!"
exit 1
fi
fi
}
# Call `_main` after everything has been defined.
_main "$@"