nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Putting multiple users in one group in one shot

This is a discussion on Putting multiple users in one group in one shot within the Shell scripting forums, part of the Development/Scripting category; Hello, to everybody, Suppose, in an organization there are 500 users. I have created one new group, let say the ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 06-22-2008, 06:52 PM
Junior Member
User
 
Join Date: Mar 2007
Posts: 8
Rep Power: 0
hrishikesh
Default Putting multiple users in one group in one shot

Hello, to everybody,

Suppose, in an organization there are 500 users. I have created one new group, let say the group is xyzabcd. I want to add about 100 users (having UID starting from 600 to 700) to that newly created group. How do I go about it?

Using usermod command I can add one user at a time to that newly created group. But I don't want to type the command for each and very user again and again. So please help me out with this situation. If with the help of script we can do this, then kindly help me out with such script, as I know little about writing the script.

Thanks in advance.

Regards,

Hrishikesh
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-23-2008, 12:36 PM
agn agn is offline
Member
User
 
Join Date: Feb 2008
My distro: OpenBSD/FreeBSD/Debian/Fedora/RHEL
Posts: 69
Rep Power: 1
agn is on a distinguished road
Default

Try something like this:

Code:
# for user in `awk -F':' '$3 >= 600 && $3 <= 700 { print $1 }' /etc/passwd`; do
> usermod -G mygroup $user
> done
Reply With Quote
  #3 (permalink)  
Old 06-23-2008, 08:41 PM
Junior Member
User
 
Join Date: Mar 2007
Posts: 8
Rep Power: 0
hrishikesh
Default

Thanks a lot, its great!. Got satisfied.

Thanks!

Regards,

Hrishikesh
Reply With Quote
Reply

Bookmarks

Tags
/etc/passwd , awk , bash , for loop , linux , shell , unix , user


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 On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Add multiple users to a group chuckbeattie Linux software 2 11-03-2007 12:04 AM
set up e-mail group karpos Mail Servers 1 06-01-2007 01:28 AM
Script to add users to multiple servers. deepakhg Shell scripting 0 03-17-2007 04:02 AM
Group Policy bubloob_13 Windows Xp/2000/2003 server administration 0 01-31-2007 03:31 PM


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


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

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