添加用户的脚本为:

#!/bin/bash
#
# a test script for add usr to system
#
#

[ $UID -eq 0 ] && echo "The current user is root"

for i in `cat /tmp/user.txt`
do
USER=`echo $i |cut -d: -f1`
PASSWD=`echo $i |cut -d: -f2`

id $USER &> /dev/null
STATE=`echo $?`
set -x
# if [ $STATE -ne 0 ]; then
if [ $STATE -eq 0 ]; then
echo "The user $USER is exist!"
echo $PASSWD|passwd --stdin $USER
echo "The user $USER passwd was changed!"
elif [ -d /home/$USER ];then
rm -rf /home/$USER
echo "the $USER home directory is deleted!"
useradd $USER
echo $PASSWD|passwd --stdin $USER
echo "The user $USER account and passwd was added"
else
echo "The user $USER is not exist!"
useradd $USER
echo $PASSWD|passwd --stdin $USER
echo "The user $USER account and passwd was added"
fi
# fi
done

#
#
# a test script for add usr to system
#
#
 
[ $UID -eq 0 ] && echo "The current user is root"
 
for i in `cat /tmp/user.txt`
        do
USER=`echo $i |cut -d: -f1`
PASSWD=`echo $i |cut -d: -f2`
 
id $USER &> /dev/null
STATE=`echo $?`
set -x
#               if [ $STATE -ne 0 ]; then
                        if [ $STATE -eq 0 ]; then
                                echo "The user $USER is exist!"
                                echo $PASSWD|passwd --stdin $USER
                                echo "The user $USER passwd was changed!"
                        elif [ -d /home/$USER ];then
                                rm -rf /home/$USER
                                echo "the $USER home directory is deleted!"
                                useradd $USER
                                echo $PASSWD|passwd --stdin $USER
                                echo "The user $USER account and passwd was added"
                        else
                                echo "The user $USER is not exist!"
                                useradd $USER
                                echo $PASSWD|passwd --stdin $USER
                                echo "The user $USER account and passwd was added"
                        fi
#               fi
        done

批量删除用户脚本:

#!/bin/bash
#
#
# ths is a scrip for del user and user's home directory
#
#
 
[ $UID -eq 0 ] && echo "the current user is ROOT"
 
for i in `cat /tmp/user.txt`
        do
USER=`echo $i |cut -d: -f1`
PASSWD=`echo $i |cut -d: -f2`
id $USER
                if [ $? -eq 0 ];then
                        userdel -r $USER
                        echo "the user and user's home directory is deleted!"
                fi
        done