View Single Post
  #2 (permalink)  
Old 31-10-2007, 06:19 PM
nixcraft's Avatar
nixcraft nixcraft is offline
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,707
Thanks: 11
Thanked 244 Times in 183 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 Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote