HowTO delete multiple users from e-smith 4.1.x

with thanks to: David O'Dwyer, Scott Smith, Dan York, Gordon Rowell (in other words, if it doesn't work, don't blame me :-)

The script below will read in a text file containing user information and automatically delete the e-smith user accounts.  This is perfect for quickly removing multiple users from e-smith.

Simply cut and paste the entire script below (including the last line "done") into a file called e-smith-deluser.sh

Then create a text file called deluserlist.txt with the following format:

USERNAME1:FIRSTNAME1:LASTNAME1
USERNAME2:FIRSTNAME2:LASTNAME2

and place both the files in the /root directory.

To execute, login as root, change to the /root directory and enter (including the "."):

[root@e-smith /root]# . e-smith-deluser.sh


#!/bin/sh
#
# USAGE:
#
# Create the file /root/deluserlist.txt in the following format:
#
# USERNAME1:FIRSTNAME1:LASTNAME1
# USERNAME2:FIRSTNAME2:LASTNAME2
#
# and so on...
#
# This script will delete user accounts, mail accounts and pseudonyms for all the listed users in the /root/deluserlist.txt file.
#
#

UFILE=/root/deluserlist.txt

if [ ! -f $UFILE ]; then
echo User database $UFILE missing
exit
fi


# export record=`cat $UFILE`
# if [ "$record" != "" ]; then

# ---------------------------------------------
# Note the lines below must be indented
# ------------------------------
     for record in `cat $UFILE`
     do
     username=`echo $record | awk -F":" {'print $1'}`
     firstname=`echo $record | awk -F":" {'print $2'}`
     lastname=`echo $record | awk -F":" {'print $3'}`

# ---------------------------------------------------------
# Delete Pseudonym (FIRSTNAME.LASTNAME@domain.org)
# Delete Pseudonym (FIRSTNAME_LASTNAME@domain.org)
# ---------------------------------------------------------
/sbin/e-smith/signal-event pseudonym-delete $firstname.$lastname $username
/sbin/e-smith/signal-event pseudonym-delete $firstname_$lastname $username

# ---------------
# Delete Username
# ---------------
/sbin/e-smith/signal-event user-delete $username

# ---------------
# Delete Account from Accounts Database
# ---------------
/sbin/e-smith/db accounts delete $username

done