您的位置:首页 > 运维架构 > Linux

批量创建用户脚本

2016-08-16 23:18 260 查看
#!/bin/bash
#create for create many users on 20160816 by babyplus
. /etc/init.d/functions
[ $UID -eq '0' ]||{
echo "use root run!"
exit 1
}
mkdir /test -p && touch /test/newuserpassword.txt
for n in `seq -w 2`
do
pass="`echo $RANDOM|md5sum |cut -c 3-8,10`"
[ `grep test${n} /etc/passwd|wc -l` -ge '1' ]&&echo "user test${n} is existed!" ||{
useradd test${n} -M &>/dev/null &&\
echo $pass |passwd --stdin test${n} &>/dev/null &&\
[ $? -eq 0 ]&&{
action "ok!" /bin/true
echo test${n}: $pass >>/test/newuserpassword.txt
}||{
action "false!" /bin/false
}
}
done
exit 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux centos useradd