Using userdel -r in a script? To delete multiple users.

I'm getting ready to upgrade to Solaris 10 (from 8) and I'm trying to write a script that will delete approximately 800 user accounts that are no longer required. I'm trying to use the userdel -r command and read the input from a file with the list of user names. I've never been very good at scripting and I'm at a lost as to where to start.

Thanks,

---------- Post updated 10-14-09 at 12:30 PM ---------- Previous update was 10-13-09 at 09:04 PM ----------

#!/bin/ksh
#
for user in $(< dellist.txt)
do
  userdel -r $user
done
#

Thanks anyone who is working this! I found my scripting book and started reading last night.

Personally I'd do it like this:

#!/bin/ksh
#
cat dellist.txt | while read user
do
        echo "Deleting: ${user}"
        echo userdel -r "${user}"
done

Remove echo on "userdel" line after thorough testing.

Ps. I know about UUOC but disagree.

Thanks! That worked also. The only problem was that with TSOL the -r didn't work. So I just repeated my for statement as follows.

#!/bin/ksh
#
for user in $(< dellist.txt)
do
userdel r $user
done
#
for user1 in $(< dellist.txt)
do
rm -rM /home/$user1
done
#

PS. I don't mind the UUOC. :slight_smile:

Will do in the future. Sorry