On Tue, 14 Dec 2010, OpenBSD Geek wrote:

Hi,

After posted many requests on how to remove user from a group, i choosed
to build my own script.
And it works very fine.

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/*
echo "Success."
else
echo "Remove user from a group"
echo "Use : sh duig user group"
fi

You really deserve the Useless Use of Cat Award.
And the race condition award, and the nuke the wrong file award, and...

Kind regards,
  Markus

Reply via email to