1.新建users.list文件并写入所要新建的用户:
jake tang monika dove david user2
:wq
2.新建useradd.sh文件:
#!/bin/bash
#
#batch add users with file called users.list
#
for username in $(more users.list)
do
if [ -n $username ]
then
useradd -m $username
echo
echo $username"123" | passwd --stdin $username
echo
echo "User $username's passwd is changed!"
else
echo "The username is null!"
fi
done
:wq
3.添加执行权限: chmod +x useradd.sh
4.两个文件放在同一个目录下,执行即可。
本文转自 zhuxtqw 51CTO博客,原文链接:http://blog.51cto.com/1054054/1256313,如需转载请自行联系原作者