The Python stdlib pwd module provides an easy way to get the primary group ID, but no way to get additional group IDs. This is a simple function that returns the additional group IDs for a given username.
1 2 | def get_additional_group_ids(username):
return [g.gr_gid for g in grp.getgrall() if username in g.gr_mem]
|