Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Getting a GID from /etc/group

by gryphon (Abbot)
on Mar 25, 2002 at 17:25 UTC ( [id://154155]=note: print w/replies, xml ) Need Help??


in reply to Getting a GID from /etc/group

Greetings c,

What others have posted already would be smarter than what I'm going to suggest. However, in the interests of contribution of all ideas, even ones that are fairly basic, here's another option:

#!/usr/bin/perl -w use strict; my $group_name = 'monks'; open(GROUPS, '/etc/group'); my $gid = (split /:/, (grep /^$group_name:/, <GROUPS>)[0])[2]; close GROUPS; print $gid, "\n"; exit;

Using getgrnam is a much better option, though. My way here assumes way too much and could therefore fail in many situations.

-gryphon
code('Perl') || die;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://154155]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-29 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found