Tom Smith wrote:
> 
> Thank Chad (and John) for your input on this. I thought I'd post the
> portion of the script that I was trying to work out to see if there's
> room for improvement. This should work on any *nix system. The format of
> the command is simple: `test.pl username`, where username is a real
> username on the system in question. Here's the script:
> 
> test.pl:
> #!/usr/bin/env perl
> 
> use strict;
> use warnings;
> 
> # Determine which Linux groups the user belongs to.
> open(FILE,'</etc/group') or die "Can't open /etc/group.";
>  
> my @memberof;
> while ($_ = <FILE>) {
>        if($_ =~ /$ARGV[0]/) {

Say that you have two users 'ron' and 'ronald'.  If $ARGV[0] contains 'ron'
then this will get you the group names for *both* 'ron' *and* 'ronald' (and
any other group names where the string 'ron' is found.)


>                my @groups = split(/:/,$_);
>                push(@memberof,$groups[0]);
>        }
> }
> 
> close FILE;
> 
> print "[EMAIL PROTECTED]";
> 
> 
> So is there a better way to do this, or perhaps a cleaner way?

Since you are only reading from /etc/group you are not picking up the primary
group stored in /etc/passwd.



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to