创建随机用户与随机密码
#!/bin/bash
User_List=$@
User_File=user.txt
for user in $User_List
do
if ! id $user &> /dev/null
then
echo "$user 不存在"
PASS=$(echo $RANDOM |md5sum | cut -c 1-8)
useradd -m -s /bin/bash $user
if [ $? -ne 0 ]
then
echo "创建用户$user失败!!"
continue
fi
echo "$user:$PASS" | chpasswd &> /dev/null
if [ $? -ne 0 ]
then
echo "创建$user用户密码失败!!"
continue
fi
echo "$user $PASS" >> $User_File
else
echo "用户$user已存在"
fi
done