View Single Post
  #1   (View Single Post)  
Old 14th December 2010
wesley wesley is offline
Real Name: Wesley
Shell Scout
 
Join Date: Aug 2009
Location: Reunion Island
Posts: 92
Post duig script - delete user in group

To delete a user, we need to edit the file : /etc/group, and remove manually the account. But if we need to remove many users, it will be very a big task.
So i built a small script that do it successfuly:

Code:
if [ $1 ] & [ $2 ]; then
cp /etc/group /tmp
cat /tmp/group | grep ^$2 > /tmp/onlygroup
cat /tmp/group | grep -v ^$2 > /tmp/nogroup
cat /tmp/onlygroup | sed "s/$1//g" | \
        sed "s/ /,/g" | sed "s/,,/,/g" | sed "s/,$//g" > /tmp/newgroup
cat /tmp/newgroup >> /tmp/nogroup
cat /dev/null > /tmp/group
cat /tmp/nogroup >> /tmp/group
cp /tmp/group /etc
chmod 644 /etc/group
chown root /etc/group
chgrp wheel /etc/group
rm -f /tmp/*
else
echo "Remove user from a group"
echo "Use : sh duig user group"
fi
Cheers,

Wesley MOUEDINE ASSABY
www.mouedine.net
Reply With Quote