Results 1 to 6 of 6
I just imported user accounts for from a list using a script. However the names on the script we just learned were created wrong by the programmer. We are talking ...
- 05-27-2005 #1Just Joined!
- Join Date
- Jan 2005
- Location
- Tennessee
- Posts
- 40
Delete users
I just imported user accounts for from a list using a script. However the names on the script we just learned were created wrong by the programmer. We are talking 800+ accounts. What is the best way to delete them? All of the UIDs are in order, if I delete the users from the /etc/passwd file, and then delete the home directories will this be sufficent. I am trying to avoid using userdel -r username for each account.
Server is Slackware 10.1 running sendmail
- 05-27-2005 #2Linux Newbie
- Join Date
- Jul 2004
- Location
- www.syracuse.com
- Posts
- 119
you could just write a bash script which contains a loop and uses the userdel program. you could execute it and walk away. i found this online and just modified it slightly. i'm not a good programer but something similar should work. please read the code first, as the numbers used are just approximations.
Code:#!/bin/bash user=1000 stop=1800 while [ "$start" -lt "$stop" ] do echo "deleting user $user" deluser '$user' user=$(($user+1)) done exit 0
- 05-27-2005 #3Just Joined!
- Join Date
- Jan 2005
- Location
- Tennessee
- Posts
- 40
Thank you, It should work because they are in order.
I need to improve my script skills!
- 05-30-2005 #4Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,043
Is deluser a special prog? It's not on FC. AFAIK you'd have to use userdel, which takes a username, not an ID.
I'd advise changing the "userdel" line into an echo so it just reports the command it'd run, the first time, just in case ...Code:#!/bin/bash start=1000 stop=1800 while [ "$start" -lt "$stop" ] do user=$(sed -n "s/\([^:][^:]*\):$start:.*/\1/p" /etc/passwd echo "deleting user $user" userdel -r "$user" start=$(($start+1)) done exit 0
- 05-30-2005 #5Just Joined!
- Join Date
- Jan 2005
- Location
- Tennessee
- Posts
- 40
Yes, I tried "userdel -r" which did not work because it saw the names to delete as those, in this case 1000 to 1800, and since there were no accounts with those names it did not delete anything.
I went ahead and deleted the lines out of the /etc/passwd file and then the home directories, so far without a hitch. My only concern is the shadow file showing accounts that no longer exit.
- 06-23-2005 #6Just Joined!
- Join Date
- Jun 2005
- Location
- Toronto, ON (Canada)
- Posts
- 8
Can anyone answer this question???. I have the same problem and cannot resolve it??? Thanks guys.I went ahead and deleted the lines out of the /etc/passwd file and then the home directories, so far without a hitch. My only concern is the shadow file showing accounts that no longer exit.


Reply With Quote
