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
Cheers,
Wesley MOUEDINE ASSABY
www.mouedine.net
I'm getting a case of nausea here. -Otto
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
Tomas already pointed out where this will blow up for sure. Hint: Take a look at mktemp(1) and install(1) to weed out the worst issues. Kind regards, Markus
... did'nt know there were such many tools,thanks.
On Tue, Dec 14, 2010 at 12:31 PM, OpenBSD Geek <openbsd@e-solutions.re> very "secure" step when you have some temporary files from daemons
Ok! Here goes my contribution to this thread!
# $1=group
# $2=user
cd /etc
cat ./group \
| sed '/'$1'/ s/'$2'//' \
| sed '/'$1'/ s/,,/,/' \
| sed '/'$1'/ s/,$//' \
| sed '/'$1'/ s/:,/:/' > group.new
mv /etc/group.new /etc/group
chown root.wheel /etc/group
chmod 644 /etc/group
exit 0
On Tue, Dec 14, 2010 at 4:00 PM, Leonardo Rodrigues A) root:wheel is better. B) it's a bad idea to fix the permissions of a file after installing it.
On Tue, Dec 14, 2010 at 10:00 PM, Leonardo Rodrigues
My take ;)
# -------------------------
FILE=/etc/group
FILE=group
install ${FILE} ${FILE}.orig
sed -e "/$1/s/$2//" \
-e "/$1/s/,,/,/" \
-e "/$1/s/,$//" \
-e "/$1/s/:,/:/" ${FILE}.orig > ${FILE}
# ----------------------------
Adriaan
Hm, that's a nice one too: for every line in /etc/group that contains '$1',
This must be the most horrible thread ever in terms of scripting and sh/ksh (ab)use I've ever seen. Please, folks, don't consider using anything posted in this thread, or god will start killing kittens.
| Greg KH | Og dreams of kernels |
| Jens Axboe | [PATCH 31/33] Fusion: sg chaining support |
| Arnd Bergmann | Re: finding your own dead "CONFIG_" variables |
| Mark Brown | [PATCH 2/2] Subject: natsemi: Allow users to disable workaround for DspCfg reset |
| Tony Breeds | [LGUEST] Look in object dir for .config |
git: | |
| Brian Downing | Re: Git in a Nutshell guide |
| John Benes | Re: master has some toys |
| Matthias Lederhofer | [PATCH 4/7] introduce GIT_WORK_TREE to specify the work tree |
| Alexander Sulfrian |
