低质量的社交,不如高质量的独处

批量添加用户

[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 ~]#

 

posted @ 2018-12-23 16:15  Eren.li  阅读(234)  评论(0编辑  收藏  举报
liweiming0611@163.com
等待有三大特征:
清晰的目的、努力达成的过程、充满不确定性的结果
因上努力,果上随缘
求其上,得其中;求其中,得其下;求其下,无所得