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 ~]#
  • 相关阅读:
    滑动条使用
    jquery日历练习
    JQuery 教程
    JS获取各种宽度、高度的简单介绍
    如何获取元素位置
    DOM练习
    DOM
    函数
    假期练习
    Uva 253 Cube painting
  • 原文地址:https://www.cnblogs.com/liweiming/p/10164639.html
Copyright © 2011-2022 走看看