• 批量添加用户


    [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 ~]#
  • 相关阅读:
    UVA 10828
    素数推断算法(高效率)
    POJ1611 The Suspects (并查集)
    Android AES加密算法及事实上现
    C语言中的内存对齐
    OpenCV——老照片效果
    uuid 学习
    OpenCV——PS 滤镜, 浮雕效果
    加密算法之BLOWFISH算法
    OpenCV——照亮边缘
  • 原文地址:https://www.cnblogs.com/liweiming/p/10164639.html
Copyright © 2020-2023  润新知