Adding user to a group without SAM

How can I add a user to a specific group without using SAM? I know I can user modprpw -G, but that will overwrite any groups the user is in with the ones I specify.

I need to assume that I do not know what groups the user is already in, so I can't put them in the modprpw command. I just need to add this user to a few groups without changing the ones they are already in.

FYI, i'm talking about secondary groups, not their primary group. And I'm scripting this, so I can't just go into /etc/group and edit it manually.

Thanks!

If you have modprpw your box must be in trusted mode so you need to use modprpw. You can obtain the list of groups a user in currently in via groups or grget commands. Then check to see if you need to add the user at all. He might already be in the group in question. If not, construct a new list of groups by adding yours to any pre-existing groups.

To get a list of groups that the user belongs to, you can use "id -a". Parse the output of that command to get the list of groups that the user belongs to. Then give the entire list to modprpw or whatever you are using.