zoukankan      html  css  js  c++  java
  • shell script 编程(2)>>批量创建账号

    学习了鸟哥的私房菜,看到帐号的批处理,就试了一遍,以下是部分代码

    #!/bash/bin
    #建立一批账号
    #2018/8/13
    export PATH=/bin:/usr/bin:/sbin:/usr/sbin
    accountfile="user.passwd"
    #账号信息的输入
    read -p "账号开头代码为 " username_start
    read -p "账号年级为 " username_degree
    read -p "账号数字位数为 " nu_nu
    
    ...
    
     -f "$accountfile" ] && mv $accountfile "$accountfile"$(date +%Y%m%d)
    nu_end=$(($nustart+$nu_amount-1))
    for((i=$nu_start ; i<=$nu_end ; i++))
    do
            nu_len=${#i}     #获取i的位数
    
            if [ $nu_nu -lt $nu_len ];then
                    echo "数字位数大于所规定的位数,程序将退出!"
                    exit 1
            fi
            nu_diff=$(($nu_nu-$nu_len))
            if [ "$nu_diff" != "0" ];then
                    nu_nn=0000000000
                    nu_nn=${nu_nn:1:$nu_diff} #代表从nu_nu字符串中第1位开始取出$nu_diff个字符
            fi
            account=${username_start}${username_degree}${nu_nn}${i}
            if [ "$pwm" == "1" ];then
                    passwd=$account
            else
                    passwd=$(openssl rand -base64 6)
            fi
            echo "$account":"$passwd" | tee -a "$accountfile"
    done
    cat "$accountfile" | cut -d ":" -f 1 | xargs -n 1 useradd -m
    chpasswd < "$accountfile"
    pwconv
    echo "OK"
    
  • 相关阅读:
    微信公众号--JS-SDK
    微信公众号--网页授权
    微信公众号--资源请求
    微信公众号--相关资料
    微信公众号--消息回复
    一.小程序 --申请
    2017年总结
    SSM框架中常用的配置文件
    UML的9种图例解析
    23种设计模式汇总整理
  • 原文地址:https://www.cnblogs.com/fjw3214/p/10705150.html
Copyright © 2011-2022 走看看