zoukankan      html  css  js  c++  java
  • 批量创建10个系统帐号,并设置密码(密码为随机数,要求字符和数字等混合)如果存在选择删除或者跳过

    1.

    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
    

      

  • 相关阅读:
    软工写文档熟练使用word很重要——自动生成编号
    UML——类图
    软件开发模型
    UML基础(终极总结)
    想买一款笔记本戴尔的InspironTM 6400
    ASP.NET 2.0 Enter Key Default Submit Button
    使用.net备份和还原数据库
    GridView导出Excel研究
    使用c#建立虚拟目录
    OpacityMask
  • 原文地址:https://www.cnblogs.com/liushuqing/p/11600039.html
Copyright © 2011-2022 走看看