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!



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
  • 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. 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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