Last active
July 30, 2016 08:45
-
-
Save drodsou/6635407 to your computer and use it in GitHub Desktop.
[bash] List users of a group in linux (as primary and as secondary)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GID=`cat /etc/group|grep $1| awk 'BEGIN { FS = ":" } ; { print $3 }'` | |
RE=".*:.*:.*:${GID}" | |
echo "As PRIMARY" | |
echo "----------" | |
cat /etc/passwd|grep $RE | awk 'BEGIN { FS = ":" } ; { print $1 }'| sort -f | awk '{print}' ORS=' ' | |
printf "\n\nAs SECONDARY\n" | |
echo "-------------" | |
cat /etc/group|grep $1 | awk 'BEGIN { FS = ":" } ; { print $4 }' |sed 's/,/\n/g' | grep '[^\$]$' | sort -f | awk '{print}' ORS=' ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment