Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just 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

  2. #2
    Linux 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

  3. #3
    Just 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!

  4. #4
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Is deluser a special prog? It's not on FC. AFAIK you'd have to use userdel, which takes a username, not an ID.
    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
    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 ...

  5. #5
    Just 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.

  6. #6
    Just Joined!
    Join Date
    Jun 2005
    Location
    Toronto, ON (Canada)
    Posts
    8
    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.
    Can anyone answer this question???. I have the same problem and cannot resolve it??? Thanks guys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •