|
|||
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 Wesley MOUEDINE ASSABY www.mouedine.net |
|
||||
Unless I misunderstood something, this is a re-invention of pw(8).
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
|||
On OpenBSD, remove user from group, can be done only modifing /etc/group.
Usermod -G, doesn't remove user on a group. |
|
|||
To Jggimi : Misc@openbsd.org and DaemonForums.org are different *
The only stupid thing i done is to post 2 times here, first in "OpenBSD General" and second in "Guides", i'm agree with you. |
|
|||
Please read the complete thread at http://marc.info/?l=openbsd-misc&m=129232689002840&w=2 before considering this script
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
Quote:
Getting compliments from Google engineers about my coding style was nice, but I didn't get the job. Point is, it takes more than "it works" for it to be correct. Last edited by rocket357; 14th December 2010 at 05:08 PM. |
|
|||
After correction, i'm agree it is a bit long, but it works.
Thank you very much for your posts! Code:
if [ $1 ] & [ $2 ]; then tempfile=`mktemp /tmp/tempfile.XXXX` cp /etc/group $tempfile onlygroup=`mktemp /tmp/tempfile.XXXX` cat $tempfile | grep ^$2 > $onlygroup nogroup=`mktemp /tmp/tempfile.XXXX` cat $tempfile | grep -v ^$2 > $nogroup cat $onlygroup | sed "s/$1//g" | \ sed "s/ /,/g" | sed "s/,,/,/g" | sed "s/,$//g" >> $nogroup install -o root -g wheel -m 644 $nogroup /etc/group rm -f /tmp/tempfile.???? else echo "Remove user from a group" echo "Use : sh duig user group" fi Last edited by wesley; 15th December 2010 at 04:14 PM. Reason: [code] shorter |
|
|||
Please, use [code] / [/code] tags when posting code. This isn't the first time someone has requested this action.
|
|
|||
The version I posted in http://marc.info/?l=openbsd-misc&m=129236670827180&w=2 is much shorter and simpler isn't it?
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
|||
Good done !
|
|
|||
As opposed to spoon-feeding, I'm going to give you a point which is going to require thought on your part, Wesley.
Consider the following line of code: Code:
tempfile=`mktemp /tmp/tempfile.XXXX` ...but I'm a nice guy. I will even give you another hint. The answer for avoiding this problem can be found on Heiner's page: http://www.shelldorado.com/ |
|
|||
thanks!
|
Tags |
duig script, openbsd |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
script add user with encrypted password | wesley | OpenBSD General | 3 | 14th December 2010 03:22 PM |
OpenBSD: create user sh script | J65nko | Guides | 3 | 31st January 2010 08:29 PM |
Canadian BSD user group.. | BSDfan666 | Off-Topic | 5 | 11th January 2009 03:37 PM |
C Programming Study Group on SDF | cajunman4life | Programming | 0 | 23rd August 2008 02:27 AM |