The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Secondary groups show in groups but don't show in id (Not working) zen03 HP-UX 4 12-31-2007 11:15 AM
Change a users primary group after login terrym UNIX for Advanced & Expert Users 3 02-09-2007 03:03 AM
Help required for usermod command gun UNIX for Dummies Questions & Answers 1 11-28-2006 05:45 AM
usermod -e amheck UNIX for Dummies Questions & Answers 1 05-23-2006 07:02 PM
Assigning existing users to a secondary group jyotipg UNIX for Dummies Questions & Answers 1 05-15-2002 03:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-02-2006
pbsrinivas pbsrinivas is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 141
usermod -G and Group id login replacing existing groups

Hi all


usermod -G Group_id login

it is replacing the existiong Secoundry groups and is adding the only group speced in usermod command

how can we retain the existing secoundry groups and add a user to a new group
  #2 (permalink)  
Old 11-02-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
The lack of an 'add' option has always bugged me too.

You can specify more than one group with -G, i.e. -G group1,group2,group3 but you'll have to extract group information somehow to get their previous groups.

Closest I've gotten to that is
Code:
egrep 'user[^:]+$' /etc/group |
        sed 's/:.*//' |
        xargs echo |
        sed 's/ /,/g'
which feels like a horrible hack for something one feels ought to be built into something else..

Last edited by Corona688; 11-02-2006 at 11:03 AM..
  #3 (permalink)  
Old 11-02-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Well, to be honest, I simply edit the /etc/group file, usermod or no usermod.
  #4 (permalink)  
Old 11-02-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
Is this a reccomended practice? It's less dangerous than editing /etc/passwd, I suppose, but could still really mess up your system if you aren't careful. It's not something you can do from a script file, either.
  #5 (permalink)  
Old 11-02-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
It may not be a recommended practice, but it is nowhere as dangerous as fiddling with /etc/passwd. Another thing, about the scripting bit. If you really want to put things into a script, look at 'ex'. I use it quite often to edit whole bunches of files, esp. on connections where I can't use vi due to the lack of proper terminal settings.

And about that hack, why not use the 'id' command? 'id -a' gives you all the info about the current user groups. You could run that, or some similar options, and pass that through sed to get the current list of groups, which you could use in the 'usermod -G' command. (Can't give any examples, no access to unix right now...)
  #6 (permalink)  
Old 11-02-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
Much better.
Code:
id -G | sed 's/ /,/g'
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0