批量创建10个系统帐号,并设置密码(密码为随机数,要求字符和数字等混合(第一种)

#!/bin/bash
for i in `seq 1 10`
do
        if id user-$i > /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 [ $? -eq 0 ];then
                echo "user-$i 创建成功"
                passwd="user`cat /dev/urandom | head -1 | md5sum | head -c 5`"
                echo "user-$i:$passwd" chpasswd
                echo "user-$i--$passwd" >> aa.txt
            else
                echo "user-$i 创建失败"
            fi
        fi
done

  

posted on 2019-10-09 10:54  运维工程师  阅读(172)  评论(0编辑  收藏  举报

导航