Last active
May 8, 2020 18:12
-
-
Save caiquearaujo/d1d06a8aaf086b2d1f62cf4d79da1f22 to your computer and use it in GitHub Desktop.
Lista todos os grupos não utilizados no sistema
This file contains hidden or 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 | |
| # Obtem o nome do grupo a ser perquisado | |
| getent group | cut -d":" -f1 | while IFS=: read -r groupname; do | |
| # Obtem o ID do groupo | |
| gid=$(cat /etc/group | grep ^"$groupname": | cut -d":" -f3) | |
| # Confere todos os usuários que utilizam o gropo | |
| used="false" | |
| for name in $(getent passwd | cut -d":" -f1); | |
| do | |
| is_member=$(id -G "$name" | grep "$gid") | |
| if [ ! -z "$is_member" ] | |
| then | |
| used="true" | |
| fi | |
| done | |
| if [ "$used" = "false" ] ; then | |
| echo "O grupo $groupname não é utilizado..." | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment