Sponsored Content
Top Forums Shell Programming and Scripting Sorting group information for accounts Post 302679817 by MaindotC on Tuesday 31st of July 2012 05:55:44 PM
Old 07-31-2012
Sorting group information for accounts

I have an input file that contains the primary and secondary groups a user should have based on a pre-defined role. The input file looks like this:

Code:
<user_login>|<comment_field>|<role>

After I execute my script to do some grepping I have the following user file where the secondary groups are defined by the role:

Code:
<user_login>|<dir_path_set_by_role>|<shell_set_by_role>|<primary_GID>|<secondary_GID>|<secondary_GID>|<secondary_GID>|...

The problem I have is that GID's must be resolved to their group name and then have the corresponding users added to an upload file that would look like your typical group entry:

Code:
<group_name>:x:<GID>:<user_1>,<user_2>,<user_3>,...

I need to sort and uniq the GID file, grep the GID in the output file to see which users require that GID, and then append them to the group upload entry. I don't know if this is necessary but I put I'm using a few temp files to store output and I'm at the part where I have all the sorted and uniq'd groups in a temp file. What I need to do is grep the GID through the user file and then append that user to the upload file where each match of the group would replace user_1, respectively. So, if my user file looked like this:
Code:
jon|/home/managers|/bin/ksh|1573|1893|4907|6135|
mike|/home/managers|/bin/ksh|1573|4907|1530||
marsha|/home/employees|/bin/ksh|739|1893||

my upload file would look like this (the GID's are translated to group names):
Code:
managers:x:1573:jon,mike
folder_1:x:1893:jon,marsha
folder_2:x:4907:jon,mike
folder_3:x:6135:jon
folder_4:x:1530:mike
employee_folder_1:x:739:marsha
employee_folder_2:x:1839:marsha,jon

Can you help me setting up the group upload file?
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Getting information from /etc/group

How can I retrieve the group id of an entry in the /etc/group file given the group name? I tried using cut and grep but cant get around the problem.. I think this problem can be solved using these commands but I dont know how (I am a newbie at this) (11 Replies)
Discussion started by: sleepster
11 Replies

2. Shell Programming and Scripting

Group on the basis of common text in the square bracket and sorting

File A 99 >ac >ss >juk 70 >acb >defa 90 >ca 100 >aa >abc >bca 85 >cde 81 >ghi >ghij 87 >def >fgh <ijk 89 >fck >ghij >kill >aa The given output shud be 100 >aa >abc >bca 87 >def >fgh <ijk 89 >fck >ghij >kill >aa (2 Replies)
Discussion started by: cdfd123
2 Replies

3. Shell Programming and Scripting

Sorting a list of filenames but keeping the path information.

Hi All I've googled around for this and can't see a way of doing it. I have a file that contains a number of records that are layed out something like the following. /path/to/directory/that/contains/a/file/I/need/filename.pdf The path itself can vary both in terms of the names and the... (7 Replies)
Discussion started by: Bashingaway
7 Replies

4. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

5. Shell Programming and Scripting

New To UNIX - Need Script to create report of user & group accounts

Hi, I'm new to the world of UNIX and have been asked to create a complex script (at least complex to me:confused:) for AIX UNIX to create a report of all the users on the server including server, user, UID, groups, GID, etc. Found a script using lsuser, but the output is still lacking. 2 things I... (2 Replies)
Discussion started by: panthur
2 Replies

6. Shell Programming and Scripting

Sorting group of records and loading last record

Hi Everyone, I have below record set. File is fixed widht file 101newjersyus 20150110 101nboston us 20150103 102boston us 20140106 102boston us 20140103 I need to group record based on first 3 letters in our case(101 and 102) and sort last 8 digit in ascending order and print only... (4 Replies)
Discussion started by: patricjemmy6
4 Replies

7. UNIX for Beginners Questions & Answers

HELP on 'sectional' or 'group' sorting

Hi, I need to do some section/group sorting. At the moment, I get around it by grep group by group and then re-directing to the same 'final' output file. Below is what's been sorted so far based on the second field $ awk -F"," '{ { print $5 " == " $6 } }' /tmp/x.csv | grep -v "^env" | grep... (2 Replies)
Discussion started by: newbie_01
2 Replies
lnewusers(1)						      General Commands Manual						      lnewusers(1)

NAME
lnewusers - Create new user accounts SYNOPSIS
lnewusers [OPTION]... DESCRIPTION
Creates new user accounts using data read from standard input. The input data consists of lines, each line has 7 colon-separated fields: User name Plaintext password User ID lnewusers refuses to create users with user ID 0 (the root user ID). Group If this field is a valid group ID, it is interpreted as a group ID, otherwise as a group name. If the field is empty, a group name equal to user name is used. If the specified group does not exist, it is automatically created. If the group is specified with a group ID, the created group has group name equal to the user name. GECOS The GECOS field is traditionally used to store user's real name and other information. Home directory If this field is empty, a default specified by libuser configuration, or /home/username if libuser configuration does not specify a default, is used. Login shell If this field is empty, a default specified by libuser configuration is used. Errors in user specifications are reported and processing continues on the next line. OPTIONS
-f, --file=file Read account data from file instead of standard input. -i, --interactive Ask all questions when connecting to the user database, even if default answers are set up in libuser configuration. -M, --nocreatehome Don't create home directories. -n, --nocreatemail Don't create mail spool files. EXIT STATUS
The exit status is 0 on success, nonzero on fatal error. Errors in user specifications are not reflected in the exit status. libuser Jul 13 2008 lnewusers(1)
All times are GMT -4. The time now is 10:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy