1 #!/bin/bash 2 for i in `seq 1 10` 3 do 4 if id tom-$i > /dev/null;then 5 read -ep "tom-$i已存在,是否删除-(y/n)" ss 6 if [ $ss = y ];then 7 userdel -rf tom-$i 8 elif [ $ss = n ];then 9 continue 10 else 11 "输入有误" 12 fi 13 else 14 useradd tom-$i 15 if [ $? -eq 0 ];then 16 echo "tom-$i 创建成功" 17 passwd="user cat /dev/random | head -1 | md5sum | head -c 5" 18 echo "tom-$1:$passwd" chpasswd 19 echo "tom-$i--$passwd" >> user.txt 20 else 21 echo "tom-$i 创建失败" 22 fi 23 fi 24 done