View Single Post

  #2 (permalink)  
Old 10-31-2007, 07:19 PM
nixcraft's Avatar
nixcraft nixcraft is offline
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,035
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
Play hard stay cool
Reply With Quote