问题
I am trying to retrieve the list of users who are not present in a particular group.
We are trying to validate an application with the user credentials through unix AIX server and the user should be present in a particular group. For now, we need to get the list of users who are not in the group (for our testing with various test scenarios).
I tried the below command to list users in a group.
"lsgroup -a users groupname"
Please help me how to use NOT ! operator for the above command or let me know if there is any other way to get users not in a group.
--Suriya
回答1:
The easiest way to do this would be to string together a couple of commands. The following example will list all users that are not in a specific group.
lsuser -a groups ALL | grep -v $GROUP |awk '{print $1}'|sort
回答2:
I hope this helps you ... easy way:
cat /etc/passwd | grep groupID GID
You can filter using grep with specific group GID.
For example you can root users using root group ID:
cat /etc/passwd | grep 0
or if you want to list all the users with their group name you can use this
awk -F':' 'NR==FNR{ a[$3]=$1; next }{ print $1", "a[$4] }' /etc/group /etc/passwd
来源:https://stackoverflow.com/questions/31472784/how-to-get-list-of-users-not-in-a-particular-group-unix-aix