for i in `seq -w 10`
do
if id user-$1 > /dev/null;then
read -ep "user-$i用户已存在,是否删除(y/n)" ss
if [ $ss = y ];then
userdel -rf user-$i
elif [ $ss = n ];then
continue
else
"输入有误"
fi
else
useradd user-$i
if [ $i -eq 0 ];then
echo "user-$i 创建成功"
passwd="user`cat /dev/random | head -1 | md5sum | head -c 5`"
echo "user-$i:$passwd" chpasswd
echo "user-$i--$passwd" >> user.txt
else
echo "user-$i 创建失败"
fi
fi
done
2
#/bin/bash
echo "创建成功的用户" > /root/user_name
read -ep "请输入要创建的用户:" num
for i in `seq 1 $num`
do
pw=`cat /dev/urandom | head -1 | md5sum | head -c 5`
id wg$i > /dev/null 2>&1
if [ $? -eq 0 ];then
while true
do
read -ep "wg$i用户已经存在,是否删掉该用用户(y/n):" select
case $select in
y|Y)
userdel -rf wg$i > /dev/null
echo "wg$i成功删除"
break
;;
n|N)
break
;;
*)
echo "输入的字符有误,请重新输入"
esac
done
else
useradd wg$i > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "wg$i用户创建成功"
echo "wg$pw" | passwd --stdin wg$i
echo "wg$i $pw " >> /root/user_name
fi
fi
done