#!/bin/bash
USERS_INFO=/root/addusers.txt
USERADD=/usr/sbin/useradd
USERDEL=/usr/sbin/userdel
PASSWD=/usr/bin/passwd
CUT=/bin/cut
while read LINES
do
USERNAME=`echo $LINES | $CUT -f1 -d' '`
PASSWORD=`echo $LINES | $CUT -f2 -d' '`
$USERADD $USERNAME
if [ $? -ne 0 ]; then
echo "$USERNAME exists, skip set;"
else
echo $PASSWORD | $PASSWD --stdin $USERNAME
fi
$USERDEL $USERNAME
if [ $? -ne 0 ]; then
echo "$USERNAME del fail;"
else
echo "$USERNAME del success;"
fi
done < $USERS_INFO
addusers.txt内容
username001 password001
username002 password002
username003 password003
username004 password004