在Linux中批量手动添加任意个用户,自定义名称,数量,密码
#!/bin/bash
# Desc: 批量添加指定个数的自定义的用户名,及密码的用户
# Author: NangongYi (E-mail:[email protected])
# Time: 2019/11/07 14:45
# 输入要定义的用户名
read -p "Please input username:" -t 30 username
# 输入要定义的用户的数量
read -p "Please input usernum:" -t 30 usernum
# 输入要定义的用户的密码
read -p "Please input userpasswd:" -t 30 userpasswd
# 对输入的三个参数进行非空验证
if [ -n $username -a -n $usernum -a $userpasswd ]
then
# 对输入的数量进行验证, 过滤所有的数字,判断是否为空
num=$(echo $usernum) | sed 's/[0-9]//g'
if [ -n $num ]
then
#验证完,遍历数量,添加指定个数的用户
for(( i=1;i<=$usernum;i=i+1 ))
do
/usr/sbin/useradd $username$i &>/tmp/null
echo $userpasswd | /usr/bin/passwd --stdin $name$i &>/tmp/null
done
fi
fi