home Mail List
Info
Info
Meetings
Goals
Upcoming
Projects
FAQ
Security
Links

[Date Prev][Date Next] [Chronological] [Thread] [Top]

[NMLUG] grep help



  Oops.  I don't do Perl...  I pretty much do bash or C.

----- Original Message ----- 
From: "Anthony Martinez" <pi@pihost.us>
To: "New Mexico Linux Users Group Mail List" <nmlug@nmlug.org>
Sent: Wednesday, March 16, 2005 8:35 PM
Subject: Re: [NMLUG] grep help


> On Wed, Mar 16, 2005 at 06:16:05PM -0700, Ed Heron
> carved this out of pure phosphors:
>> From: "Pi" <pi@pihost.us>
>> Sent: Wednesday, March 16, 2005 4:47 PM
>>
>>
>> >id -Gn <user> | grep 'groupname'
>
> Either that, or review the programmatic features of getpwent or getgrent.
> getgrent might be useful.
>
> Try something like this in perl
> #!/usr/bin/perl -w
> %mapping = ();
> $groupname = $ARGV[0] or die;
> $username = $ARGV[1] or die;
> (undef, undef, undef, $members) = getgrnam($groupname);
> foreach $user(split(' ', $members))
> {
>    $mapping{$user} = 1;
> }
> print "$username in $groupname!\n" if $mapping{$username};
>
>
> It initialises an empty mapping hash, sets the two variables off of the 
> command
> line, gets a list of the memebrs using the getgrnam function, maps the 
> list of
> users in that group into the hash, and then performs the test. This way, 
> it
> requires an exact match :)
>
> Apologies if the code above is too dense, I wrote it in like 5 mintues. If 
> you
> want me to better explain, please say so :)
>
>
>
>>
>>  Hmm.  That's interesting.  Hadn't seen that command.  That might be 
>> better
>> for what I'm doing.
>>
>> _______________________________________________
>> NMLUG mailing list
>> NMLUG@nmlug.org
>> http://www.nmlug.org/mailman/listinfo/nmlug
>
> -- 
> die_if_kernel("Whee... Hello Mr. Penguin", current->tss.kregs);
>        linux-2.2.16/arch/sparc/kernel/traps.c
> _______________________________________________
> NMLUG mailing list
> NMLUG@nmlug.org
> http://www.nmlug.org/mailman/listinfo/nmlug
> 




Please send sugestions and comments to webmaster@nmlug.org.
Valid XHTML 1.1! Valid CSS! Powered by Debian Powered by Apache