Proper way to query user and group database on a Unix host?

Mike MacCana mmaccana at
Wed Jul 23 07:47:18 CEST 2008

Hi folks,

What's the proper way to query the passwd and group database on a Unix

I'd like to fetch the users in a group (obviously from name services),
but my many varied searches can't find any reference of someone ever
looking up users on a Unix system, just NT. Weird, I know.

Currently I'm calling the getent command, which works well enough, but
surely there's a more Pythonic method of looking up OS user and group
data ...

    ## Get the full group database entry, leave just the user list, and split the list on comma
    groupsusers = commands.getoutput('getent group '+groupname).split(':',-1)[3].split(',')



Mike MacCana
Technical Specialist
Australia Linux and Virtualisation Services

IBM Global Services
Level 14, 60 City Rd
Southgate Vic 3000 

Phone: +61-3-8656-2138
Fax: +61-3-8656-2423
Email: mmaccana at

More information about the Python-list mailing list