|
List Info
Thread: Perl question
|
|
| Perl question |
  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> 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 |
  United States |
2007-09-19 18:41:25 |
|
From: sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us
> Is there is a function that returns the groups that a user is in? I know
> that I can use getgrnam <name> 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.
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">Jenda Krynicky.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 |
  United States |
2007-09-20 11:35:00 |
|
Jenda Krynicky wrote:
> From: sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us
>> Is there is a function that returns the groups that a user is in? I
>> know
>> that I can use getgrnam <name> 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.
>
> 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?
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 |
  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">sgmayo mail.bloomfield.k12.mo.us wrote:
>
> Jenda Krynicky wrote:
>> From: sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us
>>> Is there is a function that returns the groups that a user is in? I
>>> know
>>> that I can use getgrnam <name> 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.
>>
>> 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?
>
> 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 |
  United States |
2007-09-21 12:11:24 |
|
Paul Archer wrote:
> 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
>
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
> asking.
Lol, I guess that was a bit dumb.
> 11:35am, sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us wrote:
>
>>
>> Jenda Krynicky wrote:
>>> From: sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us
>>>> Is there is a function that returns the groups that a user is in? I
>>>> know
>>>> that I can use getgrnam <name> 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.
>>>
>>> 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?
>>
>> Sorry about that. I guess that I was in a hurry. This is a Linux
>> machine.
>>
>> --
>> Scott Mayo
__._,_.___
.
__,_._,___
|
| Re: Perl question Getting User Groups |
  United States |
2007-09-21 12:40:03 |
|
On 9/21/07, sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us
< sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us> wrote:
> Paul Archer wrote:
> > 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)
>
> 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
__._,_.___
|
| Re: Perl question Getting User Groups |
  United States |
2007-09-22 09:01:57 |
|
Jeff Pinyan wrote:
> On 9/21/07, sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us
> < sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us> wrote:
>> Paul Archer wrote:
>> > 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)
>>
>> 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.
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 |
  United States |
2007-09-22 13:38:40 |
|
On 9/22/07, sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us
< sgmayo%40mail.bloomfield.k12.mo.us">sgmayo mail.bloomfield.k12.mo.us> wrote:
> Jeff Pinyan wrote:
> > 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
> 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]
|
|