当前位置 博文首页 > shell脚本 自动创建用户详解及实例代码

    shell脚本 自动创建用户详解及实例代码

    作者:github_26672553 时间:2021-06-22 17:49

    shell脚本 自动创建用户详解

    需求:判断用户zhangsan是否存在,不存在就创建并设置密码为123456

    1、vi createuser.sh

    2、写入:

    USER_COUNT=`cat /etc/passwd | grep '^zhangsan:' -c`
    USER_NAME='zhangsan'
    if [ $USER_COUNT -ne 1 ]
     then
     useradd $USER_NAME
     echo "123456" | passwd $USER_NAME --stdin
     else
     echo 'user exits'
    fi
    

    3、修改createuser.sh权限

    chmod +x createuser.sh

    4、执行

    ./createuser.sh

    感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

    js
    下一篇:没有了