Groups, What am I overlooking?

DJ Lucas dj at linuxfromscratch.org
Sat Jul 17 08:32:31 PDT 2004


Guys, I'm sure this is a prime example of "ID Ten T".  I have a bad
feeling I should be asking this on linux-newbies but I guess it just 
never occured to me.  I've always done the changes by hand with an 
editor, but now I need to script it.

Listed below is the commands I've used in the interim (well sort of,
just in a sinlgle script form) to acomplish my goal, but there has got
to be an existing tool that I'm just overlooking; to just add a user to
a group without affecting the rest of his groups, isn't there?!?!?
--------------------------------------------------------
#!/bin/bash
# Begin /usr/bin/add2grp

GRUSER="$1"
NGROUPS="$2"
COUNT="3"
# Format the output of /usr/bin/groups to work nicely
# with 'usermod -G' (allows for 50 group memberships)
while [ "COUNT" != "52" ]
do
   ADDGROUP="$(/usr/bin/groups $GRUSER | cut -f "$COUNT" -d " ")"
   if [ "$ADDGROUP" != "" ]
   then
       NGROUPS="$NGROUPS,$ADDGROUP"
   fi
   let COUNT++
done
usermod -G "$NGROUPS" "$GRUSER"

# End /usr/bin/add2grp
--------------------------------------------------------

TIA

-- DJ Lucas




More information about the lfs-chat mailing list