1753544 Members
5663 Online
108795 Solutions
New Discussion юеВ

parsing /etc/group

 
SOLVED
Go to solution
Mike Hassell
Respected Contributor

parsing /etc/group

Hello All,

I have a system with 6000+ users where the /etc/group file has become unmanageable and needs to be parsed a bit so users can be manually added. I am having trouble trying to do so. Does anyone have some sed syntax that may assist with this task? As vi is running out of buffer room.

The specific group line is extremely long and is far above the 70 characters recommended. Just wondering how I should go about tending to this need? Thanks.

- Mike
The network is the computer, yeah I stole it from Sun, so what?
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: parsing /etc/group

Hi Mike:

I suspect if vi is having problems with buffer size then ed, sed, awk, etc will have also.
Perl can probably parse the file but I know you can download 'gawk' from
http://hpux.cs.utah.edu/hppd/hpux/Gnu/gawk-3.1.0/
The good news is that unlike awk, gawk has a dynamic buffer and can be as large as you set in the command line. It may work without it depending on just how big your line is.

Bear in mind, is is perfectly acceptable to have multiple group lines like this:

mygroup::45:user1,user2,user3
mygroup::45:user101,user102,user103

I had an awk script that was very close and should rewrite the file for you. It will split groups into no more than 50 users each.

Use it like this: cat /etc/group | awk (or gawk) -f split.awk > /tmp/newgroup


Clay


If it ain't broke, I can fix that.
Jordan Bean
Honored Contributor

Re: parsing /etc/group


In /etc/group, it isn't necessary to include users in their primary group.

Each line in /etc/group is limited to LINE_MAX, as defined in , typically 2048, which means about 223 users can be specified on each line.

I've used the attached perl script to cleanup /etc/group on a few systems where user management was getting out of hand.

I've also trained my account administrators to use useradd, usermod, userdel, groupadd, groupmod, and groupdel while discouraging direct editing of the passwd and group files. All of the account management scripts have also been rewritten to use the same.
Jack Werner
Frequent Advisor

Re: parsing /etc/group

One thing that reduce the size of the /etc/group file stanzas is to remove every user from their default GID group(The one in the /etc/passwd file). Also, vi has a 2048 byte buffer, so any group list that exceeds 2048 bytes will be truncated by vi. Good luck.
i'm retired
Mike Hassell
Respected Contributor

Re: parsing /etc/group

Clay & Jordan,

Your scripts work great, they both took care of my needs. I'll probably stick with using the perl script as I'm a big perl fan myself. Thanks for your time, it is appreciated greatly.

- Mike
The network is the computer, yeah I stole it from Sun, so what?