zoukankan      html  css  js  c++  java
  • 批量添加用户

    [root@server0 ~]# ll
    total 24
    -rw-------. 1 root root 8619 May  7  2014 anaconda-ks.cfg
    -rwxr-xr-x. 1 root root  336 Dec 24 00:11 batchusers
    drwxr-xr-x. 2 root root    6 Dec 16 21:06 Desktop
    drwxr-xr-x. 2 root root    6 Dec 16 21:06 Documents
    drwxr-xr-x. 2 root root    6 Dec 16 21:06 Downloads
    -rw-r--r--. 1 root root 3785 Feb 17  2017 mariadb.dump
    drwxr-xr-x. 2 root root    6 Dec 16 21:06 Music
    drwxr-xr-x. 2 root root    6 Dec 16 21:06 Pictures
    drwxr-xr-x. 2 root root    6 Dec 16 21:06 Public
    drwxr-xr-x. 2 root root    6 Dec 16 21:06 Templates
    -rw-r--r--. 1 root root   21 Dec 24 00:00 user1.txt
    drwxr-xr-x. 2 root root    6 Dec 16 21:06 Videos
    [root@server0 ~]# ./batchusers 
    Usage: /root/batchusers userfile
    [root@server0 ~]# ./batchusers  /etc/
    Input file not found
    [root@server0 ~]# ./batchusers  user1.txt 
    user yange1 is  created
    user yange2 is  created
    user yange3 is  created
    [root@server0 ~]# cat batchusers 
    #!/usr/bin/bash
    if [ $# -eq 0 ];then
        echo "Usage: /root/batchusers userfile"
        exit 1
    fi
    if [ ! -f "$1"  ];then
        echo "Input file not found"
        exit 2 
    fi
    
    for user in `cat $1`
    do
        id $user &>/dev/null
        if [ $? -eq 0 ];then
            echo "user $user already exists"
        else
            useradd $user -s /bin/false
            echo "user $user is  created"
        
        fi
    done
    [root@server0 ~]#
  • 相关阅读:
    11 对象的构造
    10 问题分析一
    9 新型的类型转换
    8 C++ 中的新成员
    7 函数重载
    6 函数参数的扩展
    5 内联函数
    查找算法总结Java实现
    九大排序算法Java实现
    帝国cms所有一级栏目遍历,如果有子栏目的话,遍历出来
  • 原文地址:https://www.cnblogs.com/liweiming/p/10164639.html
Copyright © 2011-2022 走看看