linux批量添加用户脚本

学习linux的shell脚本的时候,写了一个批量添加用户的脚本

  1 #!/bin/bash
  2 ##批量添加指定数量用户
  3 read -p "please input username : " -t 30 name
  4 read -p "please input the number of users : " -t 30 num
  5 read -p "pleaer input the password of users : " -t 30 password
  6 
  7 if [ ! -z "$name" -a ! -z "$num" -a ! -z "$password"  ]
  8         echo "进入了流程一" >> /linuxTest/userLog.log
  9         then
 10         y=$(echo $num | sed 's/[0-9]//g')
 11         if [ -z "$y" ]
 12         echo "进入了流程二" >> /linuxTest/userLog.log
 13                 then
 14                 for (( i=1;i<=$num;i=i+1 ))
 15                         do
 16                                 echo "循环第$i次" >> /linuxTest/userLog.log
 17                                 #/usr/bin/useradd $name$i & > /dev/null
 18                                 useradd $name$i & > /dev/null
 19                                 #echo $pass | /usr/bin/passwd --stdin $name$i & > /dev/null
 20                                 #change -d 0 $name$i & > /dev/null
 21                         done
 22 
 23         fi
 24 fi

刚开始用useradd的绝对路径去调用这个命令
即/usr/bin/useradd $name
可是不起作用
后面直接使用useradd的命令,就可以使用了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值