批量创建账号:提示用户输入第一个用户名(如people1)和最后一个用户名(如people10)
[[email protected] ~]# vim useradd2.sh
#!/bin/bash
read -p "please input first user: " FIRSTUSER
read -p "please input last user: " LASTUSER
FIRSTNUM=${FIRSTUSER##*[[:alpha:]]} #截取数字
LASTNUM=${LASTUSER##*[[:alpha:]]} #截取数字
NAME=${FIRSTUSER%%[0-9]*} #截取单词
for i in $(seq $FIRSTNUM $LASTNUM);do
useradd $NAME$i
echo "123" |passwd --stdin $NAME$i &>/dev/null
done
时间: 2024-12-16 21:54:43