Ubuntu 批量添加用户

#!/bin/bash

cat user.txt | while read line
do
    user=$(echo $line | cut -d ' ' -f1)
    passwd=$(echo $line | cut -d ' ' -f2)
    
    useradd -r -m -s /bin/bash $user >/dev/null
    if [ $? -eq 0 ];
    then
        echo $user":"$passwd | chpasswd
    echo "$user create success!"
    else
        echo "$user exists,skip set passwd"
    fi  
    
done

 

其中user.txt中的格式如下:

a 123

b 123

c 123

 

posted @ 2018-11-12 09:42  瞬_冷  阅读(706)  评论(0编辑  收藏  举报