Shell script to create users and set passwords in batches

First create a user.sh file and
give this file execution permission (chmod +x user.sh) The content of
vim user.sh
is as follows:


#!/bin/bash
read -p "请输入要创建的用户的数量" num
for i in `seq $num`
do
        id user$i &>/dev/null   #验证用户是否存在
        if [ $? -eq 0 ];then
                echo "用户已经创建了"
        else
                echo "用户即将开始创建"
                useradd user$i #创建用户
                echo "用户创建成功"
                echo "正在设置密码"
                sleep 5  #等待时间
                echo "123" | passwd --stdin user$i #给用户设置密码
                echo "密码设置成功"
                echo "新增加的用户是user$i"
        fi
done

Guess you like

Origin blog.csdn.net/zhangthree1/article/details/108352186