delete user in group script
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
Re: delete user in group script
On Tue, Dec 14, 2010 at 03:31:40PM +0400, 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 > > Cheers, > > Wesley MOUEDINE ASSABY > www.mouedine.net I'm getting a case of nausea here. -Otto
Re: delete user in group script
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
Re: delete user in group script
On Tue, Dec 14, 2010 at 12:31 PM, 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" | \ > B B B B 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/* very "secure" step when you have some temporary files from daemons running for your account ;-) > echo "Success." > else > echo "Remove user from a group" > echo "Use : sh duig user group" > fi > > Cheers, > > Wesley MOUEDINE ASSABY > www.mouedine.net
Re: delete user in group script
I made as I could, since it works, where is the probleme...? ;-) > 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
Re: delete user in group script
On Tue, 14 Dec 2010, OpenBSD Geek wrote: I made as I could, since it works, where is the probleme...? ;-) 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
Re: delete user in group script
On Dec 14 15:31:40, 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 Among other hilariously horrible things, this bit just made my day: > rm -f /tmp/* > echo "Success." You just nuked everybody's tempfiles. That's quite a success I guess. > else > echo "Remove user from a group" > echo "Use : sh duig user group" > fi > > Cheers, > > Wesley MOUEDINE ASSABY > www.mouedine.net
Re: delete user in group script
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 10:31 AM, Jan Stary wrote: > On Dec 14 15:31:40, 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 > > Among other hilariously horrible things, > this bit just made my day: > >> rm -f /tmp/* >> echo "Success." > > You just nuked everybody's tempfiles. > That's quite a success I guess. > > >> else >> echo "Remove user from a group" >> echo "Use : sh duig user group" >> fi >> >> Cheers, >> >> Wesley MOUEDINE ASSABY >> www.mouedine.net
Re: delete user in group script
On Tue, Dec 14, 2010 at 4:00 PM, Leonardo Rodrigues wrote: > mv /etc/group.new /etc/group > chown root.wheel /etc/group > chmod 644 /etc/group A) root:wheel is better. B) it's a bad idea to fix the permissions of a file after installing it.
Re: delete user in group script
On Tue, Dec 14, 2010 at 10:00 PM, Leonardo Rodrigues wrote: > 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 > 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
Re: delete user in group script
On Dec 14 19:00:53, Leonardo Rodrigues wrote: > Ok! Here goes my contribution to this thread! > > # $1=group > # $2=user > > cd /etc > cat ./group \ > | sed '/'$1'/ s/'$2'//' \ Hm, that's a nice one too: for every line in /etc/group that contains '$1', remove the first occurence of '$2'. Go on :-) > | 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 10:31 AM, Jan Stary wrote: > > On Dec 14 15:31:40, 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 > > > > Among other hilariously horrible things, > > this bit just made my day: > > > >> rm -f /tmp/* > >> echo "Success." > > > > You just nuked everybody's tempfiles. > > That's quite a success I guess. > > > > > >> else > >> echo "Remove user from a group" > >> echo "Use : sh duig user group" > >> fi > >> > >> Cheers, > >> > >> Wesley MOUEDINE ASSABY > >> www.mouedine.net
Re: delete user in group script
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. On 12/14/10 12:31, 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 > > Cheers, > > Wesley MOUEDINE ASSABY > www.mouedine.net
Re: delete user in group script
On Tuesday 14 December 2010 13:16:59 Markus Hennecke wrote: > On Tue, 14 Dec 2010, OpenBSD Geek wrote: > > I made as I could, since it works, where is the probleme...? ;-) > > 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.