Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a bash script that will modify /etc/group to append and delete NIS users to specific local groups on a Solaris 10u8 system. Preferable one or two functions with uid and groupname as varibles.

inputfile before adding a user myuser to groupbbb in file /etc/group




... The function should check if user is aleady part of the local group and exit

Should I use sed or nawk or something else. Anyone have a nice oneliner :-)

In linux there is gpasswd but i havent found a corresponding command in Solaris. The user are not local on the system but NIS users so usermod will not work I think!

Greatful for any pointers!


share|improve this question

Call this function:

gradd () { local group=$1 user=$2; sed "/^${group}:/{/\<${user}\>/! s/$/,${user}/}' /etc/group; }

like this:

gradd groupbbb myuser > /tmp/newgroups && mv /tmp/newgroups /etc/group

The file redirection and renaming could be moved inside the function:

gradd () { local group=$1 user=$2; sed "/^${group}:/{/\<${user}\>/! s/$/,${user}/}' /etc/group  > /tmp/newgroups && mv /tmp/newgroups /etc/group; }

then the call would be:

gradd groupbbb myuser
share|improve this answer
Hi! Many thanks, will check this out asap! /Smedis – user40797 Jun 23 '10 at 10:45
sed -i will edit a file in place. – kmarsh Jun 23 '10 at 13:09
@kmarsh: It's not available on Solaris. – Dennis Williamson Jun 23 '10 at 14:07
OK, but if he is using Bash, chances are good that he has the rest of the Gnu tools installed. – kmarsh Jun 23 '10 at 16:50
I have Gnu tools installed :-) I'm had to switch to another projct but I'will report back! /Smedis – user40797 Jun 24 '10 at 13:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.