Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Groups, Usermod

Posted on 2001-07-26
4
Medium Priority
?
391 Views
Last Modified: 2010-04-21
Using solaris

everytime I

usermod -G group1,group2,group3 username

on command line it adds these groups to the
user but does not keep the other groups for the user.

Question: how do u use usermod utility to add groups
to a user nin addition to the groups they are a member
of.

Do not answer: edit and save file. I want to know how u do it with the usermod utility.

thanks in advance.
0
Comment
Question by:zipdog44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:tdaoud
ID: 6325943
Using the usermod utility you must always specify all groups you want for a user to be member of.  Once you ommit a group it means you want the user removed from that group.

So using usermod, it is hard to add a user to a group while keeping all others without mentioning their names with -G.

Tarik
0
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 200 total points
ID: 6326852
#!/usr/bin/ksh -
logname="$1"; shift
newgroups="$*"
oldgroups="$(groups "$logname")"
print -r -- "$newgroups $oldgroups" |
sed '
s/^[ ]*//
s/[ ]*$//
s/ [ ]*/,/g
'| read allgroups
usermod -G "$allgroups" "$logname"
0
 
LVL 6

Expert Comment

by:bira
ID: 6327287
Hi
Just add a group in the last line:

    x() {
     if [ $# -ge 2 ]
     then
             for i in "$@"
             do
                     spam="$spam \"$i\""
             done
             eval chuser $spam
     fi
     }
   x groups='group1,group2,group3' username



Regards
0
 
LVL 3

Expert Comment

by:gcauthon
ID: 6328005
usermod -G `groups <username> |sed 's/ /,/g'`,group1,group2,group3 <username>
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question