How to get list of users not in a particular group - unix aix

此生再无相见时 提交于 2019-12-12 02:19:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!