Sponsored Content
Top Forums Shell Programming and Scripting Script to list primary group of users Post 302461734 by Aswex on Tuesday 12th of October 2010 06:16:09 AM
Old 10-12-2010
Script to list primary group of users

Dear All

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 :


Code:
#!/bin/ksh -p

touch fic_ListGRP_tmp.log
touch fic_ListUSR_tmp.log
touch fic_results_tmp.log

cat /etc/group | grep ONE | awk 'BEGIN{FS=":"}{print $1}' >> fic_ListGRP_tmp.log
for groupe in `cat fic_ListGRP_tmp.log` ;
do
cat /etc/group | grep ${groupe} | awk 'BEGIN{FS=":"} {print $4}' | sed 's/,/ /g' > fic_ListUSR_tmp.log
for user in `cat fic_ListUSR_tmp.log`
do
group_prim=`cat /etc/passwd | grep $user: | awk 'BEGIN{FS=":"}{print $4}' | head -1`
name_groupe=`cat /etc/group | grep ":$group_prim:" | awk 'BEGIN{FS=":"}{print $1}'`
echo "$user $group_prim $name_groupe" | tee -a >> fic_results_tmp.log

\rm ${fic_ListGRP_tmp.log}
\rm ${fic_ListUSR_tmp.log}



done
done

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 help.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find All Primary and Secondary Group ID's for a user

Is there any command which can list me all the Group ID's (Primary, Secondary ) assocaited with a single user. Thanks Sanjay (2 Replies)
Discussion started by: sanjay92
2 Replies

2. UNIX for Dummies Questions & Answers

command help, how do i list the users of a group?

What command allows you to display a list of the userids of all the other users in a group, regardless if they are logged in or not? (3 Replies)
Discussion started by: crabtruck
3 Replies

3. Solaris

How do you list users in a solaris group

I need to list all users in a group. This is a large unix site running nis+. (6 Replies)
Discussion started by: gillbates
6 Replies

4. UNIX for Advanced & Expert Users

Change a users primary group after login

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)
Discussion started by: terrym
3 Replies

5. Shell Programming and Scripting

List ALL users in a Unix Group (Primary and Secondary)

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)
Discussion started by: ckmehta
5 Replies

6. AIX

script for finding all the users with GID 0 ( admin group )

Hi Friends, I am trying to write a script for finding all the users with the GID 0 i.e. Admin users. can you please help me on this. (1 Reply)
Discussion started by: anoopraok
1 Replies

7. Ubuntu

primary group for user

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)
Discussion started by: presul
2 Replies

8. Shell Programming and Scripting

Script to add new users to a group on multiple servers using SSH

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)
Discussion started by: Satya1983
1 Replies

9. UNIX for Beginners Questions & Answers

Primary group

Is it possible user without a primary group (3 Replies)
Discussion started by: lobsang
3 Replies

10. HP-UX

Creating a group of users with script

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
NEWSLOG(5)							File Formats Manual							NEWSLOG(5)

NAME
newslog - description of Usenet log files DESCRIPTION
Most log files created by Usenet programs reside in the /var/log/news directory and have a ``.log'' extension. Several versions are usu- ally kept with an additional extension such as ``.1'', ``.2'', etc. -- the higher the number, the older the log. The older versions are compressed. The scanlogs script and related utilities (see newslog(8)) are responsible for rotating and compressing these files. Some log files always have data, others only have data if there is a problem, and others are only created if a particular program is used or configuration parameter is set. The innstat script (see newslog(8)) monitors the size of all log files. The following files will only accumulate data under the direction of control.ctl(5): control.log miscctl.log newgroup.log rmgroup.log unwanted.log In order to create these files, the ``message'' and ``action'' fields of control.ctl should be chosen from the following table: Message Action Meaning all log=miscctl Log all messages by default default log=miscctl Log unknown messages newgroup doit=newgroup Create group and log message newgroup log=newgroup Log message rmgroup doit=rmgroup Remove group and log message rmgroup log=rmgroup Log message ``other'' doit=miscctl log and process the message ``other'' log=miscctl Log message Here, ``other'' refers to any other control message such as: checkgroups ihave sendme sendsys senduuname version The following is a list of log files. control.log This file maintains a count of the number of newgroup and rmgroup control messages seen for each newsgroup. The count is of the number of control messages with identical arguments, regardless if they were actually processed. All control arguments, including invalid ones, are counted. This file is updated by tally.control, which is invoked by scanlogs if either the newgroup or rmgroup logs exist. This file is not rotated. errlog This file contains the standard output and standard error of any program spawned by innd(8). The most common programs are the con- trol-message handlers found in /usr/lib/news/control. This file should be empty. Scanlogs will print the entire contents of this log file if it is non-empty. expire.log By default, when news.daily is going to expire old news articles, it writes the date to this file, followed by any output from expire(8) and the ending date. All lines but the first are indented four spaces. miscctl.log When control.ctl is configured as described above, all control messages except newgroup and rmgroup are appended to this file by writelog. There will be a summary line describing the message and the action taken, followed by the article indented by four spa- ces, and a blank line. newgroup.log When control.ctl is configured as described above, all newgroup messages are appended to this file using the same format as for mis- cctl.log. news This file logs articles received by innd. Scanlogs summarizes the rejected articles reported in this file. news.crit All critical error messages issued by innd are appended to this file via syslog(3). This log file should be empty. Scanlogs will print the entire contents of this log file if it is non-empty. You should have the following line in your syslog.conf(5) file: news.crit /var/log/news/news.crit news.err All major error messages issued by innd are appended to this file via syslog. This log file should be empty. Scanlogs will print the entire contents of this log file if it is non-empty. You should have the following line in your syslog.conf file: news.err /var/log/news/news.err news.notice All standard error messages and status messages issued by innd are appended to this file via syslog. Scanlogs uses the awk(1) script innlog.awk to summarize this file. You should have the following line in your syslog.conf file: news.notice /var/log/news/news.notice nntpsend.log The nntpsend(8) programs appends all status messages to this file. rmgroup.log When control.ctl is configured as described above, all rmgroup messages are appended to this file using the same format as for misc- ctl.log. unwanted.log This log maintains a count of the number of articles that were rejected because they were posted to newsgroups that do not exist at the local site. This file is updated by tally.unwanted and maintained in reverse numeric order (the most popular rejected group first). This file is not rotated. HISTORY
Written by Landon Curt Noll <chongo@toad.com> and Rich $alz <rsalz@uunet.uu.net> for InterNetNews. This is revision 1.6, dated 1996/09/10. SEE ALSO
control.ctl(5), ctlinnd(8), expire(8), innd(8), news.daily(8), nntpsend(8), newslog(8). NEWSLOG(5)
All times are GMT -4. The time now is 10:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy