useradd.sh
#!/bin/bash
user_file=/root/user.txt
for user in $(cat $user_file)
do
if ! id $user &>/dev/null;then
pass=$(echo $RANDOM | md5sum | cut -c 1-8)
useradd $user
echo $pass | passwd --stdin $user &>/dev/null
echo "$user <---> $pass" >> /root/user_list.txt
echo "$user user create successful."
else
echo "$user user already exists!"
fi
done
验证:
[root@logstash ~]# cat user.txt
zhangsan1
zhangsan2
zhangsan3
zhangsan4
zhangsan5
[root@logstash ~]# sh useradd.sh
zhangsan1 user create successful.
zhangsan2 user create successful.
zhangsan3 user create successful.
zhangsan4 user create successful.
zhangsan5 user create successful.
[root@logstash ~]# cat user_list.txt
zhangsan1 <---> c697081b
zhangsan2 <---> be5ac8fb
zhangsan3 <---> 5f290521
zhangsan4 <---> 655087a3
zhangsan5 <---> e5b664ec
[root@logstash ~]#
[root@logstash ~]# tail -n5 /etc/passwd
zhangsan1:x:1010:1010::/home/zhangsan1:/bin/bash
zhangsan2:x:1011:1011::/home/zhangsan2:/bin/bash
zhangsan3:x:1012:1012::/home/zhangsan3:/bin/bash
zhangsan4:x:1013:1013::/home/zhangsan4:/bin/bash
zhangsan5:x:1014:1014::/home/zhangsan5:/bin/bash
[root@logstash ~]#
标签:bin,shell,批量,successful,create,user,linux,root,logstash
From: https://blog.51cto.com/ztj1216/12046514