批量加用户脚本

批量加用户脚本

创建100个系统用户,登录用户名取值范围为(exam0~exam99)用户登录密码与其用户名相同,用户的默认shell为要求为bash,用户的home目录要求在/home 下的与其用户名相同的文件夹下;这100个用户的uid应该从1001开始依次向后排列,同时这些用户都应该属于gid为1001的study组。
这个脚本怎么写?
你看过鸟哥的私房菜没有?第三版的??哪里面有介绍,而且还有一个事例,也是讲的如何批量的添加用户!!你可以看看!好像是在shell脚本这一章!   脚本这个东西我也在学习中,不是太懂!所以.......你看看鸟哥的介绍吧!
 
 
===
#!/bin/bash
read -p "您想要创建多少个用户:" count
i=1
name=user
while [ $i -le $count ]
do
if [ $i -le 9 ];then
i=0$i
fi
useradd $name$i
i='expr $i + 1'
done
-------------------------------------------------
自己修改下

 
=====
 
我就拿十个来搞~~

[root@alibaba ~]# cat useradd
#!/bin/bash
groupadd study -g 1001
for i in $(seq 0 9)
do
  ii=$[ $i+1000 ]
  useradd exam$i -s /bin/bash -u $ii -g study
  echo exam$i | passwd --stdin exam$i
done

++++++++++++++++++++++++++++++++++++++++++++++++++

[root@alibaba ~]# ./useradd
Changing password for user exam0.
passwd: all authentication tokens updated successfully.
Changing password for user exam1.
passwd: all authentication tokens updated successfully.
Changing password for user exam2.
passwd: all authentication tokens updated successfully.
Changing password for user exam3.
passwd: all authentication tokens updated successfully.
Changing password for user exam4.
passwd: all authentication tokens updated successfully.
Changing password for user exam5.
passwd: all authentication tokens updated successfully.
Changing password for user exam6.
passwd: all authentication tokens updated successfully.
Changing password for user exam7.
passwd: all authentication tokens updated successfully.
Changing password for user exam8.
passwd: all authentication tokens updated successfully.
Changing password for user exam9.
passwd: all authentication tokens updated successfully.
[root@alibaba ~]# tail -10 /etc/passwd
exam0:x:1000:1001::/home/exam0:/bin/bash
exam1:x:1001:1001::/home/exam1:/bin/bash
exam2:x:1002:1001::/home/exam2:/bin/bash
exam3:x:1003:1001::/home/exam3:/bin/bash
exam4:x:1004:1001::/home/exam4:/bin/bash
exam5:x:1005:1001::/home/exam5:/bin/bash
exam6:x:1006:1001::/home/exam6:/bin/bash
exam7:x:1007:1001::/home/exam7:/bin/bash
exam8:x:1008:1001::/home/exam8:/bin/bash
exam9:x:1009:1001::/home/exam9:/bin/bash
 
========
 
 
 
从板凳的理念出发~~
[root@alibaba ~]# cat useradd
#!/bin/bash
groupadd study123 -g 3001
read -p "创建用户数:" count
for i in $(seq 0 "$count")
do
  ii=$[ $i+3000 ]
  useradd exama$i -s /bin/bash -u $ii -g study123
  echo exama$i | passwd --stdin exama$i
done
 
 
 
 
========
建立10个系统账户,并加入到yewu组的脚本
#!/bin/bash
i=1
groupadd yewu
while  [ $i -le 10  ]
do
if  [ $i -le 10   ] ;then
useradd stu0$i -g yewu
else
useradd stu$i  -g yewu
fi
let i++
done
 
 
===========
 
 
交互式建立账户的脚步
#!/bin/bash
echo -n  "please input a username:"
read AA
useradd $AA -s /sbin/nologin
echo "$AA" | passwd --stdin $AA &> /dev/null
echo -n "Do you want to setup another user?(yes/no)"
read BB
while [ $BB = yes  ]
do
echo -n  "please input a username:"
read EE
useradd $EE -s /sbin/nologin
echo "$EE" | passwd --stdin $EE &> /dev/null
echo -n "Do you want to setup another user?(yes/no)"
read BB
done
 
 
====
循环语句  比如for   
   
useradd    home目录自动解决了

密码那 可以用  echo username:passwd | chpasswd     相关位置 变量代替
 
====
 
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23141985/viewspace-704838/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23141985/viewspace-704838/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值