Re: Displaying a user's group memberships
- From: perrin@xxxxxxxxxxxx (Chad Perrin)
- Date: Mon, 18 Dec 2006 17:16:01 -0700
On Mon, Dec 18, 2006 at 04:50:57PM -0700, Tom Smith wrote:
I need to capture a user's group memberships for further processing in a
Perl script. The user's username is passed to the script via the command
line and captured with ARGV. From there, I want to determine the group
memberships (much like executing `groups` from the command line) and run
those through a loop for processing.
I seem to be having a problem locating a function that will do this.
I've looked at several and tried a couple, but either I'm doing
something wrong or I'm using the wrong functions. All of the ones I've
tried are part of getgr*.
I'm very new to Perl so maybe I'm just looking for the wrong terms or
something. I've googled and searched perldoc.perl.org.
Can anyone offer any suggestions or point me in the right direction?
Thanks, in advance, for your help!
A simple solution that comes immediately to mind is to iteratively check
for the user's name in lines of the /etc/group file, and grab the first
field (before the first colon) of each line that matches. This'll give
you a list of groups. There are likely other, more elegant solutions to
the problem, but that's the first that springs to mind.
It'd require some regex use for matching, and either a regex or split()
to separate the first field. It should be extremely simple to write
with only basic understanding of the language and very simple
understanding of Perl regex syntax, but I'm not providing code so that I
don't just do your work for you. Let us know if you have any problems
with the concepts.
relevant perldocs:
perldoc perlre
perldoc -f split
perldoc perlintro
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"The measure on a man's real character is what he would do
if he knew he would never be found out." - Thomas McCauley
.
- Follow-Ups:
- Re: Displaying a user's group memberships
- From: Tom Smith
- Re: Displaying a user's group memberships
- References:
- Displaying a user's group memberships
- From: Tom Smith
- Displaying a user's group memberships
- Prev by Date: Displaying a user's group memberships
- Next by Date: How do I tell perl -w: "I really want to use this var just once"
- Previous by thread: Displaying a user's group memberships
- Next by thread: Re: Displaying a user's group memberships
- Index(es):
Relevant Pages
|
|