Linux学习小标兵,专注Linux资讯分享,技术文章分享
分类: LINUX
2019-09-17 21:55:18
[root@localhost ~]# vim /root/users.txt //新建一个取值列表 xiaozhang xiaoli xiaowang xiaosun [root@localhost ~]# vim useraddfor.sh //创建批量创建用户的脚本 #!/bin/bash ULIST=$(cat /root/users.txt) for UNAME in $ULIST do useradd $UNAME echo "123456" | passwd --stdin $UNAME &> /dev/null done [root@localhost ~]# sh useraddfor.sh //执行脚本 [root@localhost ~]# tail -4 /etc/passwd //验证效果 xiaozhang:x:1001:1001::/home/xiaozhang:/bin/bash xiaoli:x:1002:1002::/home/xiaoli:/bin/bash xiaowang:x:1003:1003::/home/xiaowang:/bin/bash xiaosun:x:1004:1004::/home/xiaosun:/bin/bash
[root@localhost ~]# vim useraddwhile.sh #!/bin/bash PREFIX="stu" i=1 while [ $i -le 10 ] do useradd ${PREFIX}$i echo "123456" | passwd --stdin ${PREFIX}$i &> /dev/null let i++ done [root@localhost ~]# sh useraddwhile.sh [root@localhost ~]# tail /etc/passwd stu1:x:1005:1005::/home/stu1:/bin/bash stu2:x:1006:1006::/home/stu2:/bin/bash stu3:x:1007:1007::/home/stu3:/bin/bash stu4:x:1008:1008::/home/stu4:/bin/bash stu5:x:1009:1009::/home/stu5:/bin/bash stu6:x:1010:1010::/home/stu6:/bin/bash stu7:x:1011:1011::/home/stu7:/bin/bash stu8:x:1012:1012::/home/stu8:/bin/bash stu9:x:1013:1013::/home/stu9:/bin/bash stu10:x:1014:1014::/home/stu10:/bin/bash
本文来自《Linux就该这么学》官方资讯站。