I need help with users ASAP
Hey guys first time on the forums. first a little overview of my setup.
1 Slackware Server, 1 windows 2000 Server (for certain applications that run off windows, and about 250 some odd computers maybe less. I have the Slackware setup to run as a "Primary samba server" and all works fine. Heres the user file system: Home dir: /home/group/user Shares: /shares/share1 /shares/share2 /shares/share3 and so on "i also have shares that only a certain group of users can access." here are my groups: Admin Teachers NHS2011 <--- the 20xx is the graduation year for the students NHS2012 <-----| NHS2013 <-------| I have a script that alows me to brezz through and add all the users. Now is it possible that i can have a script that asks for the group name and it will manualy find all users in that group and delete them and the delete the group for example the following commands: userdel -r user1 userdel -r user2 userdel -r user3 groupdel group_of_users1 rm /home/group_of_users1 i can do it manualy but it takes a very long time... at the end of the school year we have to delete 100 - 150 names... and as you can see this would take a long long time. so i came up with the idea to just open an xwindo sesion and open /homes/group *delete it /etc/passwd *delete entrys for the users in the group /etc/samba/smbpasswd *delete entrys for the users in the group but, this is still a long drown out process as far as scrolling though the passwd and smbpasswd lists. Im sure there is an esier way to do this thanks for any help. |
Yes, there is. You can create a shell script which would iterate through the users of a particular group and delete all users from both Linux and Samba, and then delete the group. Forgive me for not posting any examples, but I don't have anything like that in my repository (and while most of my scripts are Open Source, I do get paid for creating custom work). Basically, you would read the /etc/group file, grepping it for the group you wanted to delete, then for each user in the group, run userdel -r and smbpasswd -x, then do groupdel for the group.
A good place to start with Bash scripts is "Learning the Bash Shell" from Oreilly. |
Quote:
although it will be hard for me to find time to learn bash, i know a little, enough to write the "newuser" script I mentioned earlier. But, im not sure how much i would need to learn and how long it would take me to write that script. So, if any one had a script that they would be willing to part with i'd be very greatfull. Thanks, |
Oooh, programming exercise, fun :)
Code:
#! /bin/bash |
OK, I took pity on you :-) This script should do what you want, except it will not delete users if it's their primary group (in which case, they don't appear in /etc/group as members of the group). Run with care.
Code:
#!/bin/bash |
Thanks
Thanks, i really appreciate it.
I'll try it first thing Monday morning! |
hey i run the script heres what i get
root@server:~# groupdelete nhs2010 ERROR: There were no users found for group nhs2010 root@server:~# heres how i modified the script: Code:
#!/bin/bash |
Possibly it should be NHS2010 not nhs2010
|
no, becouse if that was so it wouldn't find the user group so there for it would show the error message:
"ERROR: Group NHS2010 not found in /etc/group" i made sure the group name was in lower case i checked the group and directorys it's nhs----* thanks though, any one have some ideas? |
Ah, you're right about that, I just assumed it was uppercase because that's what you had in your first post.
Try running grep nhs2010 /etc/group, if it comes up with something add the cut: Code:
grep nhs2010 /etc/group | cut -f4 -d: |
The script allready contains "cut"
Code:
# Delete all users belonging to this group, then delete the group. NOTE: Since its the weekend and a holiday on Monday i cant get to the server untill Tuesday. Is it possible that the command checking if the grep command worked corectly have the wrong santax? If so what is the right santex? Code:
if [ -z $USERLIST ]; then |
OH hey wait a minute i just red this
Quote:
Is there still a way you can do this by using the nhs2010 group name? |
Quote:
Code:
grep nhs2010 /etc/group Code:
grep nhs2010 /etc/group | cut -f4 -d: Quote:
Code:
#!/bin/bash |
tanks, ill try it when i get a chance. Looks good, great job
|
ntubski: My original code did not take into account if the group was the user's primary group, in which case they wouldn't be listed as users in the group file. Thanks for the mod to handle this.
|
All times are GMT -5. The time now is 02:36 PM. |