Sorry, I sent this to the poster rather than the list... My bad.

-------- Original Message --------
Subject:        Re: Displaying a user's group memberships
Date:   Wed, 20 Dec 2006 20:39:13 -0700
From:   Tom Smith <[EMAIL PROTECTED]>
To:     John W. Krahn <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>



John W. Krahn wrote:
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.)

Sorry, couldn't help myself... Had to check in to it tonight. :-D Here's what seems to work in the Rx Toolkit...

[:,]$ARGV[0][,\s]

So we basically just check for a ":" or "," before the username and a "," or " " (space) after the username. This should prevent matching "ron" in "ronald", as in your example. I tested it on a few other similar names and had the same results--only the complete username was matched.

I haven't tested it in the program yet, but my tests in Rx Toolkit provide the expected results. I'll try it in the script tomorrow and see how it goes.

Thanks again for the great advice!

~ Tom.

--
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