Results 1 to 3 of 3

Thread: Add multiple users to a group

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Location
    Asheville, NC
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    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

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,515
    Thanks
    17
    Thanked 815 Times in 511 Posts
    Rep Power
    10

    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.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Junior Member
    Join Date
    Oct 2007
    Location
    Asheville, NC
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

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

    chuck

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. set up e-mail group
    By karpos in forum Mail Servers
    Replies: 1
    Last Post: 1st June 2007, 01:28 AM
  2. Script to add users to multiple servers.
    By deepakhg in forum Shell scripting
    Replies: 0
    Last Post: 17th March 2007, 04:02 AM
  3. Group Policy
    By bubloob_13 in forum Windows Xp/2000/2003 server administration
    Replies: 0
    Last Post: 31st January 2007, 03:31 PM
  4. Group Policy
    By bubloob_13 in forum Windows Xp/2000/2003 server administration
    Replies: 1
    Last Post: 20th December 2006, 04:22 PM
  5. win2k3 Group policy
    By bubloob_13 in forum Windows Xp/2000/2003 server administration
    Replies: 1
    Last Post: 11th December 2006, 01:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •