nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Add multiple users to a group

This is a discussion on Add multiple users to a group within the Linux software forums, part of the Linux Getting Started category; Can someone help me? I want to be able to add multiple users to a group. Is there a script ...

Go Back   nixCraft Linux Forum > Linux Getting Started > Linux software

Linux answers from nixCraft.


Linux software General questions and discussion about Redhat/Fedora Core/Cent OS, Debian and Ubuntu Linux related to softwares should go here.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-30-2007, 08:34 PM
Junior Member
User
 
Join Date: Oct 2007
Location: Asheville, NC
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
chuckbeattie is on a distinguished road
Send a message via Yahoo to chuckbeattie
Default Add multiple users to a group

Can someone help me? I want to be able to add multiple users to a group.

Is there a script that will allow me to do this? The users already exist I would like to add them to a particular group.



thanks

chuck
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-31-2007, 06:19 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
Posts: 1,527
Thanks: 2
Thanked 18 Times in 15 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Assuming that usernames are in users.txt file
Code:
user1
user2
user3
user4
Here is the script, that keep old member ship and add user to new groups defined by $nGROUPS, as usual backup /etc/group and other files before running script:
Code:
#!/bin/bash
INPUT=users.txt
USERS=$(cat $INPUT)
nGROUPS="ftp, sales"
mGROUPS=""
for u in $USERS
do
 pGgroups="$(id -Gn ${u} | sed -e 's/ /,/g')"
 mGROUPS="${pGgroups},${nGROUPS}"
 # old version 
 usermod -G $mGROUPS $u
 # new version group add needs no hack
 # usermod -a $nGROUPS $u
done
Above script is just demonstration, feel free to modify as per your UNIX / Linux setup.
__________________
Vivek | My personal blog
Linux Evangelist
+ ADD [SOLVED] thread prefix to your thread when your problem is sorted out by editing your thread.
+ Always use CODE tags for posting system output and commands!
Reply With Quote
  #3 (permalink)  
Old 11-02-2007, 11:04 PM
Junior Member
User
 
Join Date: Oct 2007
Location: Asheville, NC
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
chuckbeattie is on a distinguished road
Send a message via Yahoo to chuckbeattie
Default

Thanks, I will try this. Thank you for your help.

chuck
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
set up e-mail group karpos Mail Servers 1 06-01-2007 12:28 AM
Script to add users to multiple servers. deepakhg Shell scripting 0 03-17-2007 03:02 AM
Group Policy bubloob_13 Windows Xp/2000/2003 server administration 0 01-31-2007 02:31 PM
Group Policy bubloob_13 Windows Xp/2000/2003 server administration 1 12-20-2006 03:22 PM
win2k3 Group policy bubloob_13 Windows Xp/2000/2003 server administration 1 12-11-2006 12:30 PM


All times are GMT +5.5. The time now is 02:24 AM.


Powered by vBulletin® Version 3.8.3 - Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36