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
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
Assuming that usernames are in users.txt file
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:user1 user2 user3 user4
Above script is just demonstration, feel free to modify as per your UNIX / Linux setup.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
All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]
Thanks, I will try this. Thank you for your help.
chuck
There are currently 1 users browsing this thread. (0 members and 1 guests)