Secondary user groups

G

gga

require 'etc'
Etc.getpwnam(user)

or, using Daniel Berger's std-admin library_

require 'sys/admin'
Sys::Admin.get_user(user)

allows me to get a struct with the user's primary group.

However, I need to obtain the list of ALL groups that a user belongs
to (primary and secondary).
Other than doing the unportable:

groups = `groups #{user}`.split

is there a method in the ruby std library to get the secondary groups?
 
G

gga

require 'etc'
Etc.getpwnam(user)

or, using Daniel Berger's std-admin library_

require 'sys/admin'
Sys::Admin.get_user(user)

allows me to get a struct with the user's primary group.

However, I need to obtain the list of ALL groups that a user belongs
to (primary and secondary).
Other than doing the unportable:

groups = `groups #{user}`.split

is there a method in the ruby std library to get the secondary groups?

Never mind. Found how to do it.
 
D

Daniel Berger

Gregory said:
Well how did you do it? ;)

Here's one way you could do it with sys-admin:

groups = []
Admin.groups{ |g|
groups << g.name if g.members.include?('you')
}

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top