List Info

Thread: Perl question




Perl question
country flaguser name
United States
2007-09-19 16:30:13

Is there is a function that returns the groups that a user is in? I know
that I can use getgrnam <name&gt; to get a list of members of that group, but
I was wanting the opposite. I want to feed it a user name and get a list
of groups for that user.

I know that I can parse through each group and get it that way, but I
wanted to make sure there was not already a built-in function for it.

Thanks.

--
Scott Mayo
System Administrator
Bloomfield Schools

__._,_.___
.

__,_._,___
Re: Perl question
country flaguser name
United States
2007-09-19 18:41:25

From: sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us
&gt; Is there is a function that returns the groups that a user is in? I know
>; that I can use getgrnam <name&gt; to get a list of members of that group, but
> I was wanting the opposite. I want to feed it a user name and get a list
>; of groups for that user.
&gt;
> I know that I can parse through each group and get it that way, but I
> wanted to make sure there was not already a built-in function for it.

Usually it helps to say what operatiing system do you use when asking
somehintg apparently OS dependent. You would not want me to suggest
Win32::AdminMisc, would you?

Jenda
===== Jenda%40Krynicky.cz">JendaKrynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

__._,_.___
.

__,_._,___
Re: Perl question
country flaguser name
United States
2007-09-20 11:35:00


Jenda Krynicky wrote:
&gt; From: sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us
&gt;> Is there is a function that returns the groups that a user is in? I
>&gt; know
>;> that I can use getgrnam <name&gt; to get a list of members of that group,
&gt;> but
>> I was wanting the opposite. I want to feed it a user name and get a
>&gt; list
>;> of groups for that user.
&gt;>
&gt;> I know that I can parse through each group and get it that way, but I
>&gt; wanted to make sure there was not already a built-in function for it.
>
> Usually it helps to say what operatiing system do you use when asking
&gt; somehintg apparently OS dependent. You would not want me to suggest
> Win32::AdminMisc, would you?

Sorry about that. I guess that I was in a hurry. This is a Linux machine.

--
Scott Mayo
System Administrator
Bloomfield Schools
PH: 573-568-5669
FA: 573-568-4565

Gun Control: Belief that violent predators willing to ignore laws against
robbery, kidnapping, rape, and murder will obey a law telling them that
they cannot do so with a gun.

__._,_.___
.

__,_._,___
Re: Perl question
country flaguser name
United States
2007-09-20 11:40:44

You probably just want the 'id' command:
$ id parcher
uid=1000(parcher) gid=1000(parcher)
groups=1000(parcher),4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),104(scanner),112(netdev),113(lpadmin),115(powerdev),117(fuse),118(admin),122(usb)

Paul

PS You should try to come up with a better subject line. Those of us on this
group kind of make the assumption that it is a 'Perl question' that you're
asking.

11:35am, sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us wrote:

>
&gt; Jenda Krynicky wrote:
&gt;> From: sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us
&gt;>> Is there is a function that returns the groups that a user is in? I
>&gt;> know
>;>> that I can use getgrnam <name&gt; to get a list of members of that group,
&gt;>> but
>>> I was wanting the opposite. I want to feed it a user name and get a
>&gt;> list
>;>> of groups for that user.
&gt;>>
>>&gt; I know that I can parse through each group and get it that way, but I
>&gt;> wanted to make sure there was not already a built-in function for it.
>>
>> Usually it helps to say what operatiing system do you use when asking
&gt;> somehintg apparently OS dependent. You would not want me to suggest
>> Win32::AdminMisc, would you?
>;
> Sorry about that. I guess that I was in a hurry. This is a Linux machine.
>
>; --
> Scott Mayo
>; System Administrator
> Bloomfield Schools
> PH: 573-568-5669
> FA: 573-568-4565
>
> Gun Control: Belief that violent predators willing to ignore laws against
> robbery, kidnapping, rape, and murder will obey a law telling them that
>; they cannot do so with a gun.
>;
>

----------------------------------------------------------
"They're willing to kill people. That makes them dangerous."
--News announcer, about South American drug lords
----------------------------------------------------------

-----10989 days until retirement!-----

__._,_.___
.

__,_._,___
Re: Perl question Getting User Groups
country flaguser name
United States
2007-09-21 12:11:24

Paul Archer wrote:
&gt; You probably just want the 'id' command:
> $ id parcher
> uid=1000(parcher) gid=1000(parcher)
&gt; >groups=1000(parcher),4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),104(scanner),112(netdev),113(lpadmin),115(powerdev),117(fuse),118(admin),122(usb)
>;
> Paul
>;

I use the id command when I am in the OS command line, but I did not see
anything in my book that said it was a function in Perl. I could use the
'system' command to run it, but how do I get the groups into variables
then?

Thanks.

Scott

> PS You should try to come up with a better subject line. Those of us on
> this
>; group kind of make the assumption that it is a 'Perl question' that you're
&gt; asking.

Lol, I guess that was a bit dumb.

> 11:35am, sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us wrote:
&gt;
>&gt;
>&gt; Jenda Krynicky wrote:
&gt;>> From: sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us
&gt;>>> Is there is a function that returns the groups that a user is in? I
>&gt;>> know
>;>>&gt; that I can use getgrnam <name&gt; to get a list of members of that group,
&gt;>>> but
>>>>; I was wanting the opposite. I want to feed it a user name and get a
>&gt;>> list
>;>>&gt; of groups for that user.
&gt;>>&gt;
>&gt;>> I know that I can parse through each group and get it that way, but I
>&gt;>> wanted to make sure there was not already a built-in function for it.
>>>
>>>; Usually it helps to say what operatiing system do you use when asking
&gt;>> somehintg apparently OS dependent. You would not want me to suggest
>>>; Win32::AdminMisc, would you?
>;>
>;> Sorry about that. I guess that I was in a hurry. This is a Linux
&gt;> machine.
>>
>> --
>&gt; Scott Mayo

__._,_.___
.

__,_._,___
Re: Perl question Getting User Groups
country flaguser name
United States
2007-09-21 12:40:03

On 9/21/07, sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us
&lt; sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us> wrote:
&gt; Paul Archer wrote:
&gt; > You probably just want the 'id' command:
> > $ id parcher
> > uid=1000(parcher) gid=1000(parcher)
&gt; > >groups=1000(parcher),4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),104(scanner),112(netdev),113(lpadmin),115(powerdev),117(fuse),118(admin),122(usb)
>;
> I use the id command when I am in the OS command line, but I did not see
> anything in my book that said it was a function in Perl. I could use the
> 'system' command to run it, but how do I get the groups into variables
> then?

You don't use system() to get the output of a command into variables.
You use backticks (``) or the qx operator for that.

chomp( ($uid_gid, $groups) = `id $username` );

Parsing the contents of $uid_gid and $groups is an exercise for you.

--
[Mary said,] "Do whatever he tells you." ~ John 2:5

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Find Enlightenment

Yoga groups and

resources on

Yahoo! Groups.

Re: Perl question Getting User Groups
country flaguser name
United States
2007-09-22 09:01:57


Jeff Pinyan wrote:
&gt; On 9/21/07, sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us
&gt; < sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us> wrote:
&gt;> Paul Archer wrote:
&gt;> > You probably just want the 'id' command:
>> > $ id parcher
>> > uid=1000(parcher) gid=1000(parcher)
&gt;> > >groups=1000(parcher),4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),104(scanner),112(netdev),113(lpadmin),115(powerdev),117(fuse),118(admin),122(usb)
>;>
>;> I use the id command when I am in the OS command line, but I did not
>> see
>> anything in my book that said it was a function in Perl. I could use
>> the
>> 'system' command to run it, but how do I get the groups into variables
>> then?
&gt;
> You don't use system() to get the output of a command into variables.
> You use backticks (``) or the qx operator for that.
&gt;
> chomp( ($uid_gid, $groups) = `id $username` );
>
> Parsing the contents of $uid_gid and $groups is an exercise for you.

I did not realize that. Actually that command pulls everything into
$uid_gid though. It would be nicer if I could just pull out group
numbers, but I can parse through that fine I believe. I'll see which is
easier. To parse that line or to just read in all the groups and see if
the user is in it.

Thanks for the info.

--
Scott Mayo
System Administrator
Bloomfield Schools
PH: 573-568-5669
FA: 573-568-4565

Gun Control: Belief that violent predators willing to ignore laws against
robbery, kidnapping, rape, and murder will obey a law telling them that
they cannot do so with a gun.

__._,_.___
.

__,_._,___
Re: Perl question Getting User Groups
country flaguser name
United States
2007-09-22 13:38:40

On 9/22/07, sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us
&lt; sgmayo%40mail.bloomfield.k12.mo.us">sgmayomail.bloomfield.k12.mo.us> wrote:
&gt; Jeff Pinyan wrote:
&gt; > chomp( ($uid_gid, $groups) = `id $username` );
>
> I did not realize that. Actually that command pulls everything into
>; $uid_gid though. It would be nicer if I could just pull out group
&gt; numbers, but I can parse through that fine I believe. I'll see which is
> easier. To parse that line or to just read in all the groups and see if
> the user is in it.

Oh, sorry. I thought the output was on two lines, but it turns out
that's an artifact of the email message itself (a really long line
that had to be broken).

--
[Mary said,] "Do whatever he tells you." ~ John 2:5

__._,_.___
.

__,_._,___
[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )