I am facing a problem with my script.
I have to found the primary group of users .
So first I selected all the groups and users register from a specific user : ONE
Then I am making a file with all groups attached to the user : ONE
Then I am making a file with all users from each group of that user : ONE Then for each user I have to found his primary group
Ex : Groups of USER ONE
GRP1 ::111 :ONE,TWO,THRE
GRP2 ::2848 :SIX ;ONE,SEVEN
and so one
Here is the script that i have writen :
My problem is the number of users listed is by far beyond of the userlist.
I've got 151 users but at the end the list contain 298 entries .... I can't find what is wrong.
thanks for your quick reply. I've to give to my boss all primary group of all users from all groups where the user ONE exist.
Exemple if the user ONE exist on the GRP1 and GRP2 I have to see if there some other users in GRP1 and GRP2 and if yes, what is the primary group of thoses users.
I found that the problem come from that specific line :
I found that there is some exact lines two or three times.
I need a specific pattern on result as I have to give an excel file.
First off, there are several syntactical problems in your script:
I don't know what this is supposed to do, but most probably it won't do it, whatever "it" is.
Second, i don't know which system you are working on. If it is some Linux or Linuxoid system you can simply get all the primary groups of all the users by reading field 4 in the file /etc/passwd. If you need the groups name just refer to /etc/group for a name-GID relation. See the code-snippet below:
The reason why your code might have failed is not clear. One possibility is that you counted users more than one times: suppose user ONE has groups A, B, C, D, user B has groups "A, C, D". Per your algorithm you would find user account B three times and count it for three distinct users. To avoid this you will have to make your list with users unique by filtering out all the doubles, probably by filtering the fnal list through "sort -u" or something such.
I am on solaris 9. I also believed the line code below is not good as there is two or three times the exact same lines with the same users. This why my result log contains more users than I have if I am making manually the print screen of the command. I belived the for loop can't work as I need.
I hope you may be help me to make it right.
Thanks
---------- Post updated at 08:00 AM ---------- Previous update was at 07:13 AM ----------
Dear Friends,
thanks a lot for your help. I solved my problem. Sorry for making all of you searching to help me. I am so glad to have you for help.
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)
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 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)
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)
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)