0

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

2 Answers2

0

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
acer123
  • 326
  • 1
  • 15
  • It is not working. It is listing me the usage patterns for grep command as "usage: grep [-r] [-R] [-H] [-L] [-E|-F] [-c|-l|-q] [-insvxbhwyu] [-p[parasep]] -e pattern_list..." – Suriya Rakhunathan Jul 22 '15 at 09:49
  • i want users who are all not in group 'XYZ'. Following your command, i gave the command as lsuser -a groups ALL | grep -v $XYZ |awk '{print $1}'|sort please let me know if i gave the command in correct way – Suriya Rakhunathan Jul 22 '15 at 09:50
  • please give me the output of the following command: which grep – acer123 Jul 22 '15 at 12:14
  • "/usr/bin/grep" this was the output. is there any other options to list down the users? Please help – Suriya Rakhunathan Jul 27 '15 at 12:41
  • The $GROUP is a variable. You don't type that in. You type in what the actual group is that you are interested in. So, an example would be: lsuser -a groups ALL | grep -v staff | awk '{print $1}' | sort – acer123 Jul 27 '15 at 18:22
0

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
kvantour
  • 25,269
  • 4
  • 47
  • 72