1.建立一个用户名的文件,如下
vim /shell/students.txt
hankunfa1
hankunfa2
hankunfa3
2.编写shell脚本
vim /shell/useradd.sh
#!/bin/bash
cat /shell/students.txt |while read STUdo
id $STU >/dev/null 2>&1
if [ $? -eq 0 ];then
echo "the user $STU is exist ,please give me another name "
else
useradd $STU
echo "123456"|passwd --stdin $STU >/dev/null 2>&1
echo "the user $STU has been created"
fi
done
执行命令
/bin/bash /shell/useradd.sh
本文介绍了一种使用Shell脚本来批量创建系统用户的方法。通过读取包含用户名的文本文件,脚本会逐行处理每个用户名,检查其是否存在,若不存在则创建该用户并设置默认密码。
3420

被折叠的 条评论
为什么被折叠?



