Just for interest, here is a belt-and-braces approach which does not need workfiles.
Throughout it does an exact match on every lookup. It also deals with the problem of duplicates which can happen if another user appears more than once in the same secondary group list as the user "ONE".
Code:
username="ONE"
(
# Find all secondary groups for $username
groups -g "${username}" | tr " " "\n" | while read group_name
do
# Find primary group of all members of each $group_name
listusers -g "${group_name}" | awk '{print $1}'|while read member
do
# Look up $member in /etc/passwd and output username and group
awk -F: '{if ($1 == member) {print $1,$4; exit}}' member=$member /etc/passwd
done
done
# Eliminate duplicates
) | sort | uniq | while read username2 group_no2
do
# Convert primary group number into group name
group_name2="`awk -F: '{if ($3 == group) {print $1; exit}}' group=$group_no2 /etc/group`"
echo "${username2} ${group_no2} ${group_name2}" > fic_results_tmp.log
done
When users login, they are directed to menu (aix script). The menu enables the user to choose an environment to work in. Each environment has a different group id. When a user chooses a menu option, I want to change his primary group to that specific environment's group id. Is this at all possible... (3 Replies)
Is there a command or better combination of cmds that will give me the list of Unix users in a particular Unix group whether their primary group is that group in question (information stored in /etc/passwd) or they are in a secondary group (information stored in /etc/group).
So far all I got... (5 Replies)
HI
I need to know what is the primary group name of a particular user.
How to do this ?
Maybe with groups cmd ? (first group name in line, is the primary group)
thx for help. (2 Replies)
Hi Experts,
I am new to scripting. We have around 400 Linux servers in our environment. I want to add a new user to a perticular group on all the servers using SSH.
Requirements:
1) Need to take the server names from a text file.
2) Login into each server and check whether perticular... (1 Reply)
Hi,
I have a file with usernames, and the comment section, e.g :
Data removed by request of sanchitadutta91, 20 May 2020
I need to add these users into a server. Is it possible to use a script to create the users, together with the comment ?
From the commandline to add one user, the... (2 Replies)
Discussion started by: anaigini45
2 Replies
LEARN ABOUT MINIX
group
GROUP(5) Linux Programmer's Manual GROUP(5)NAME
group - user group file
DESCRIPTION
The /etc/group file is a text file that defines the groups on the system. There is one entry per line, with the following format:
group_name:password:GID:user_list
The fields are as follows:
group_name the name of the group.
password the (encrypted) group password. If this field is empty, no password is needed.
GID the numeric group ID.
user_list a list of the usernames that are members of this group, separated by commas.
FILES
/etc/group
BUGS
As the 4.2BSD initgroups(3) man page says: no one seems to keep /etc/group up-to-date.
SEE ALSO chgrp(1), gpasswd(1), groups(1), login(1), newgrp(1), sg(1), getgrent(3), getgrnam(3), gshadow(5), passwd(5)COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
Linux 2016-10-08 GROUP(5)