DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 14th December 2010
wesley wesley is offline
Real Name: Wesley
Fdisk Soldier
 
Join Date: Aug 2009
Location: Reunion Island
Posts: 76
Thanked 1 Time in 1 Post
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
  #2   (View Single Post)  
Old 14th December 2010
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,088
Thanked 198 Times in 156 Posts
Default

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.
Reply With Quote
  #3   (View Single Post)  
Old 14th December 2010
wesley wesley is offline
Real Name: Wesley
Fdisk Soldier
 
Join Date: Aug 2009
Location: Reunion Island
Posts: 76
Thanked 1 Time in 1 Post
Default

On OpenBSD, remove user from group, can be done only modifing /etc/group.
Usermod -G, doesn't remove user on a group.
Reply With Quote
  #4   (View Single Post)  
Old 14th December 2010
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,088
Thanked 198 Times in 156 Posts
Default

Right, it wasn't clear that this is on OpenBSD.

You may also want to edit your first post and put the actual code inside [code] tags, this will preserve tabs and spaces, which will make your code much more readable.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
  #5   (View Single Post)  
Old 14th December 2010
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,891
Thanked 214 Times in 189 Posts
Default

Wesley, I no longer bother responding to your threads here on Daemonforums. You duplicate the exact same question/issue/comment on misc@ each and every time.
Reply With Quote
  #6   (View Single Post)  
Old 14th December 2010
wesley wesley is offline
Real Name: Wesley
Fdisk Soldier
 
Join Date: Aug 2009
Location: Reunion Island
Posts: 76
Thanked 1 Time in 1 Post
Default

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.
Reply With Quote
  #7   (View Single Post)  
Old 14th December 2010
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,249
Thanked 182 Times in 149 Posts
Default

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
Reply With Quote
  #8   (View Single Post)  
Old 14th December 2010
rocket357's Avatar
rocket357 rocket357 is offline
Real Name: Jonathon
Wannabe OpenBSD porter
 
Join Date: Jun 2010
Location: 127.0.0.1
Posts: 338
Thanked 9 Times in 9 Posts
Default

Quote:
I made as I could, since it works, where is the problem...? ;-)
I had a job interview at Google last summer, and they asked me the question "You have a command to run on 100,000 machines. How do you approach it?" I wrote a very classy threaded Python program to utilize their existing key-based infrastructure to ssh simultaneously to all 100,000 machines as fast as my workstation could launch child threads. As each child thread successfully established an ssh connection, it would issue the command to the machine it was connected to. The program would then gather the results from each child thread in a directory hierarchy on my local machine so I could grep -R the output for issues. It was awesome....but it answered the wrong question. They asked about my approach (which by my program I implied "I'd just run the command, f*ck it"). They were looking for "I'd run it on a single test machine and wait a bit to see if it caused problems. If it appeared to be ok, I'd run it on a bigger group and wait again. If that was ok, I'd write a program (much like my python code) to run it on everyone."

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.
Reply With Quote
  #9   (View Single Post)  
Old 14th December 2010
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 576
Thanked 14 Times in 13 Posts
Default

Nits of widely varying sizes could be picked in OP's script, but I'll be content with one piece of low-hanging fruit, presumably run as root:

Code:
rm -f /tmp/*
!
Reply With Quote
Old 15th December 2010
wesley wesley is offline
Real Name: Wesley
Fdisk Soldier
 
Join Date: Aug 2009
Location: Reunion Island
Posts: 76
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
Old 15th December 2010
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 2,935
Thanked 190 Times in 160 Posts
Default

Please, use [code] / [/code] tags when posting code. This isn't the first time someone has requested this action.
Reply With Quote
Old 15th December 2010
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,249
Thanked 182 Times in 149 Posts
Default

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
Reply With Quote
Old 15th December 2010
wesley wesley is offline
Real Name: Wesley
Fdisk Soldier
 
Join Date: Aug 2009
Location: Reunion Island
Posts: 76
Thanked 1 Time in 1 Post
Default

Good done !
Reply With Quote
Old 16th December 2010
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 2,935
Thanked 190 Times in 160 Posts
Default

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`
...& what is done with it for the remainder of the script when multiple people are running the script on the same machine at the same time. Hint, it isn't good.

...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/
Reply With Quote
Old 16th December 2010
wesley wesley is offline
Real Name: Wesley
Fdisk Soldier
 
Join Date: Aug 2009
Location: Reunion Island
Posts: 76
Thanked 1 Time in 1 Post
Default

thanks!
Reply With Quote
Reply

Tags
duig script, openbsd

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 12:07 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick