Hi,
I am working on a script that would run on Solaris and I need a Perl
script/function/module that would give me the list of groups that a
user belongs to- just like the Unix groups command. Could someone
please help?
Regards,
Tanveer
|
|
0
|
|
|
|
Reply
|
arshad.tanveer (4)
|
3/15/2007 1:47:20 PM |
|
arshad.tanveer@gmail.com wrote:
> Hi,
> I am working on a script that would run on Solaris and I need a Perl
> script/function/module that would give me the list of groups that a
> user belongs to- just like the Unix groups command. Could someone
> please help?
Please have a look at the posting guidelines.
What have you tried so far and where did your code not meet your=20
expectations?
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
|
|
0
|
|
|
|
Reply
|
Josef
|
3/15/2007 1:54:24 PM
|
|
On Mar 15, 6:54 pm, Josef Moellers <josef.moell...@fujitsu-
siemens.com> wrote:
> arshad.tanv...@gmail.com wrote:
> > Hi,
> > I am working on a script that would run on Solaris and I need a Perl
> > script/function/module that would give me the list of groups that a
> > user belongs to- just like the Unix groups command. Could someone
> > please help?
>
> Please have a look at the posting guidelines.
> What have you tried so far and where did your code not meet your
> expectations?
>
> --
> These are my personal views and not those of Fujitsu Siemens Computers!
> Josef M=F6llers (Pinguinpfleger bei FSC)
> If failure had no penalty success would not be a prize
> -- T. Pratchett
I haven't tried anything because I don't even know where to start.
Googl'ing for answers, I came across functions like getgrnam but they
give a list of users in a group. I want it the other way round. Given
a user id, how to determine the groups?
Thanks,
Tanveer
|
|
0
|
|
|
|
Reply
|
arshad
|
3/15/2007 2:16:44 PM
|
|
arshad.tanveer@gmail.com wrote:
> On Mar 15, 6:54 pm, Josef Moellers <josef.moell...@fujitsu-
> siemens.com> wrote:
>=20
>>arshad.tanv...@gmail.com wrote:
>>
>>>Hi,
>>>I am working on a script that would run on Solaris and I need a Perl
>>>script/function/module that would give me the list of groups that a
>>>user belongs to- just like the Unix groups command. Could someone
>>>please help?
>>
>>Please have a look at the posting guidelines.
>>What have you tried so far and where did your code not meet your
>>expectations?
>=20
> I haven't tried anything because I don't even know where to start.
> Googl'ing for answers, I came across functions like getgrnam but they
> give a list of users in a group. I want it the other way round. Given
> a user id, how to determine the groups?
You mean: you don't know anything about Perl? Or you don't know anything =
about where Solaris keeps this information?
One of the major features of Perl are its text processing abilities.
Usually Un*x base systems keep the information about users and groups in =
text files in /etc (I would be surprised if Solaris did otherwise).
So, adding 1(text processing features) and 1(information kept in text=20
files) together should get you started. If you have problems getting the =
first line of Perl code into the machine or onto a sheet of paper, this=20
group is definitely the wrong place to start. Better get a decent book,=20
e.g. the camel book, and start reading.
You wrote "I'm working os a script ...", so you must at least have=20
something to start with.
Eeven if you post a rudimentary program that shows that you at least=20
tried to do some work yourself, you'll find legions of people willing to =
help (well, maybe not legions).
This is not a group to ask for ready-to-use solutions.
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
|
|
0
|
|
|
|
Reply
|
Josef
|
3/15/2007 2:35:45 PM
|
|
On 03/15/2007 08:47 AM, arshad.tanveer@gmail.com wrote:
> Hi,
> I am working on a script that would run on Solaris and I need a Perl
> script/function/module that would give me the list of groups that a
> user belongs to- just like the Unix groups command. Could someone
> please help?
>
> Regards,
> Tanveer
>
Read about the "getgrent" function:
Start->Run->"perldoc -f getgrent"
-------
Posting Guidelines for comp.lang.perl.misc:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
|
|
0
|
|
|
|
Reply
|
Mumia
|
3/15/2007 2:40:25 PM
|
|
arshad.tanveer@gmail.com wrote:
> Hi,
> I am working on a script that would run on Solaris and I need a Perl
> script/function/module that would give me the list of groups that a
> user belongs to- just like the Unix groups command. Could someone
> please help?
The "just like the unix groups command" sound makes this sound like a
self-answering question to me.
my @groups = split " ", `groups $user`;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
|
|
0
|
|
|
|
Reply
|
xhoster
|
3/15/2007 3:26:00 PM
|
|
arshad.tanveer@gmail.com wrote:
>
> I am working on a script that would run on Solaris and I need a Perl
> script/function/module that would give me the list of groups that a
> user belongs to- just like the Unix groups command. Could someone
> please help?
my $user = 'tanveer';
my @groups = scalar getgrgid( ( getpwnam $user )[ 3 ] );
while ( my ( $name, $users ) = ( getgrent )[ 0, -1 ] ) {
$users =~ /\b$user\b/ and push @groups, $name
}
print "$user : @groups\n";
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
|
|
0
|
|
|
|
Reply
|
John
|
3/15/2007 3:31:47 PM
|
|
On Thu, 15 Mar 2007 15:35:45 +0100 Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
JM> This is not a group to ask for ready-to-use solutions.
Why not?
I like to know if a ready-made solution exists for many common Perl
tasks all the time, so I don't write them myself.
What's wrong is expecting people to write the solution for you, which
Arshad did not do. He clearly asked for a module/function/solution to
help him in the course of writing a script, to get the list of groups
for a user. Why does he have to attempt to write such a common task
himself, given that it's probably been done already a million times?
Let's be sensible. I understand the Posting Guidelines are important,
but they should not override common sense.
Ted
|
|
0
|
|
|
|
Reply
|
Ted
|
3/15/2007 6:00:06 PM
|
|
On 2007-03-15 14:35, Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
> arshad.tanveer@gmail.com wrote:
>> On Mar 15, 6:54 pm, Josef Moellers <josef.moell...@fujitsu-
>> siemens.com> wrote:
>>>arshad.tanv...@gmail.com wrote:
>>>>I am working on a script that would run on Solaris and I need a Perl
>>>>script/function/module that would give me the list of groups that a
>>>>user belongs to- just like the Unix groups command. Could someone
>>>>please help?
[...]
>> I haven't tried anything because I don't even know where to start.
>> Googl'ing for answers, I came across functions like getgrnam but they
>> give a list of users in a group. I want it the other way round. Given
>> a user id, how to determine the groups?
>
> You mean: you don't know anything about Perl? Or you don't know anything
> about where Solaris keeps this information?
>
> One of the major features of Perl are its text processing abilities.
> Usually Un*x base systems keep the information about users and groups in
> text files in /etc (I would be surprised if Solaris did otherwise).
Solaris likes to use NIS. LDAP is also quite popular these days.
So the text file case may be less usual than you think.
However, regardless on how the information is actually stored, using the
getpw* and getgr* functions should always work. To find all groups a
user belongs to, you have to get the primary group with getpw(uid|nam)
and then loop over all groups returned by getgrent and check for each
group whether the user is a member. AFAIK there is no faster portable
way to do this.
hp
--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | | hjp@hjp.at | the circumlocutions of bureaucrats.
__/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
|
|
0
|
|
|
|
Reply
|
Peter
|
3/15/2007 6:17:44 PM
|
|
On 2007-03-15 14:40, Mumia W. <paduille.4060.mumia.w+nospam@earthlink.net> wrote:
> On 03/15/2007 08:47 AM, arshad.tanveer@gmail.com wrote:
>> I am working on a script that would run on Solaris and I need a Perl
^^^^^^^
>> script/function/module that would give me the list of groups that a
>> user belongs to- just like the Unix groups command. Could someone
>> please help?
>
> Read about the "getgrent" function:
>
> Start->Run->"perldoc -f getgrent"
It's been some time that I've used Solaris, but I think the
"Start->Run->" part of your advice doesn't work there :-).
hp
--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | | hjp@hjp.at | the circumlocutions of bureaucrats.
__/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
|
|
0
|
|
|
|
Reply
|
Peter
|
3/15/2007 6:19:33 PM
|
|
Ted Zlatanov wrote:
> On Thu, 15 Mar 2007 15:35:45 +0100 Josef Moellers <josef.moellers@fujit=
su-siemens.com> wrote:=20
>=20
> JM> This is not a group to ask for ready-to-use solutions.
>=20
> Why not?
>=20
> I like to know if a ready-made solution exists for many common Perl
> tasks all the time, so I don't write them myself. =20
>=20
> What's wrong is expecting people to write the solution for you, which
> Arshad did not do. He clearly asked for a module/function/solution to
> help him in the course of writing a script, to get the list of groups
> for a user. Why does he have to attempt to write such a common task
> himself, given that it's probably been done already a million times?
>=20
> Let's be sensible. I understand the Posting Guidelines are important,
> but they should not override common sense.
I'm afraid you're right: I have over-reacted a little and apologize to=20
Arshad.
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
|
|
0
|
|
|
|
Reply
|
Josef
|
3/16/2007 10:04:53 AM
|
|
|
10 Replies
192 Views
(page loaded in 0.166 seconds)
|