shell脚本交互式批量创建用户:
#!/bin/sh
#Interactive bulk user creation
#num:Number of users created
#num>0
declare -i num
read -p 'Please enter the number of users to create:' num
for i in `seq 1 $num`
do
read -p "Please enter the username of the $i user you want to create:" username
useradd $username
echo "Please give the user:$username a password!"
passwd $username
done
shell脚本批量创建用户,用户名定义为stu(1~n),用户密码初始化为:123456,第一次登录时强制修改密码
num为你要创建的用户的数量
#!/bin/sh
#Create users in batches with an initial password of 123456, and force the password to be changed at the first login
#num:Number of users created
#num>0
declare -i num
read -p 'Please enter the number of users to create:' num
for i in `seq 1 $num`
do
useradd stu$i
echo "The user:stu$i is initial password is 123456!"
echo 123456 |passwd --stdin stu$i
chage -d 0 stu$i
done