TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:14115] Listing members of a group.



On Sun, 27 Feb 2000, Steve Paltzer wrote:

> For example, I want to get a list for the members of the group ‘users'
> 
> "prompt>some_command group_name
> agent, xtype, NoseGoblin, etcetera."

Hey Steve --
	while I suppose I could poke & prod you in the right direction
until you figure it out on your own, my perl muscles are in need of
flexing. I should also state that anyone who knows me knows that I
would like to say "you could also do that with awk!" 
That said, here is the code you need: 
#!/usr/bin/perl

open(GROUP, "/etc/group");

while(<GROUP>) {
        @a = split(/:/, $_);
        if($a[0] =~ /$ARGV[0]/) {
                @b = split(/\,/, $a[3]);
                foreach $c (@b) {
                        print $c . "\n";
                }
        }
}
close(GROUP);

just give it the group you want on the command-line, and there you go....
And the CGI version, using the most rudimentary HTML possible, is:
#!/usr/bin/perl

open(GROUP, "/etc/group");

print "<HTML>";
print "</BODY>";
while(<GROUP>) {
        @a = split(/:/, $_);
        if($a[0] =~ /$ARGV[0]/) {
                @b = split(/\,/, $a[3]);
                foreach $c (@b) {
                        print $c . "<BR>";
                }
        }
}
print "</BODY>";
print "<HTML>";
close(GROUP);



~Dan D.
____________________________________________________________________
--  I know you think you thought you knew what you thought I said,
--  but I'm not sure you understood what you thought I meant.

++  Dan Debertin
++  Systems Administrator
++  Router Geek
++  Bitstream Underground, Inc.
++  danield@bitstream.net
++  (612)321-9290