Shell脚本添加用户
#/bin/bash #注释你要执行的文件理解 (执行shell脚本自动添加用户) user=$(cat /root/user.txt) for users in user do useradd $users echo "123456" | passwd — stdin $users &> /dev/null done
然后我们在编辑好一个名字叫user的txt文件
vim /root/user.txt
zhangsan (随意输入要添加的用户)可无限写
然后我们wq保存退出
这样就是一个简简单单的shell脚本
出来后我们给第一个test1.sh加入可执行权限
chmod +x test1.txt
执行sh文件
sh test1.sh 也可以 . test1.sh 或者直接 sh test1.sh
最后我们可以查看一下/etc/passwd
tail /etc/passwd
就可以看到运用shell脚本中来添加输入到user.txt文件中输入到文件里的用户名字了。