zoukankan      html  css  js  c++  java
  • shell--写一个脚本,批量创建10个用户用户名为userAdd1-10,并给他们随机密码

    1,创建十个用户,并且给予随机密码,并将密码保存到一个文件中

    #!/bin/bash
    ##############################################################
    # File Name: add.sh
    # Version: V1.0
    # Author: ZhangHongLiang
    # Organization: 
    # Created Time : 2017-12-08 11:55:42
    # Description:
    ##############################################################
    source /etc/init.d/functions
    for((i=01;i<=10;i++));do
    user=addUser$i
    password=`uuidgen`
      echo "$user" >>/tmp/pass.txt
      echo "$password" >>/tmp/pass.txt
      echo "--------------------$user--------------------"
    useradd $user
      if [ $? != 0 ];then
        action "user $user" /bin/false
        exit 1
        else
        action "user $user" /bin/true
    fi   
    echo "$password"|passwd --stdin $user
      if [ $? != 0 ];then
        action "user $password" /bin/false
        exit 1
        else
        action "user $password" /bin/true
    fi   
      echo "--------------------$user--------------------"
    done

    2.创建一个脚本,批量删除上一个脚本所创建的用户

    #!/bin/bash
    ##############################################################
    # File Name: userdel.sh
    # Version: V1.0
    # Author: ZhangHongLiang
    # Organization: 
    # Created Time : 2017-12-08 17:18:18
    # Description:
    ##############################################################
    . /etc/init.d/functions
    for((i=1;i<=10;i++));do
    user=addUser$i
    userdel -r $user
      if [ $? != 0 ];then
        action "userdel $user" /bin/false
        exit 1
        else
        action "userdel $user" /bin/true
    fi
    done
  • 相关阅读:
    使用yeoman搭建脚手架并发布到npm
    Facebook的一些基本操作(网页版)
    Egg中使用egg-mongoose和常用的Mongoose 方法
    Vuex的使用
    跨浏览器的javascript事件的封装
    利用ngnix解决跨域问题
    webpack打包工具
    用vue-cli脚手架搭建一个仿网易云音乐的全家桶vue项目
    mac 解决mysqlclient安装失败问题
    linux之wget
  • 原文地址:https://www.cnblogs.com/ExzaiTin/p/8006378.html
Copyright © 2011-2022 走看看