学习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的命令,就可以使用了