#!/bin/bash
#批量创建用户,并且随机设置密码,首次登陆必须修改密码
#创建的用户存放在一个文档内。通过附加参数导入
#所创建的用户,密码保存在userpass.txt中
function rootness(){
if [[ $EUID -ne 0 ]]; then
echo "Error:This script must be run as root!" 1>&2
exit 1
fi
}
function cuser(){
for NAME1 in `cat $1`
do
id $NAME1 &> /dev/null
if [ $? -eq 0 ];then
echo "The uesr ${NAME1} is exists"
# exit 1
else
useradd $NAME1
PASS=`date | md5sum | base64 | cut -b 1-8` &> /dev/null
echo "$PASS" | passwd --stdin ${NAME1} &> /dev/null
passwd -e $NAME1 &> /dev/null
echo " user $NAME1 password: ${PASS}" | tee -a /root/userpass.txt
fi
}
rootness
cuser