把需要创建的用户名放在一个文件里,然后自动创建这些用户
效果图
代码如下:
效果图
![](http://img.blog.itpub.net/blog/attachment/201610/12/31098809_1476241138G8p8.png?x-oss-process=style/bb)
![](http://img.blog.itpub.net/blog/attachment/201610/12/31098809_1476241485l1Oo.png?x-oss-process=style/bb)
代码如下:
点击(此处)折叠或打开
- #!/bin/bash
- read -p "please enter the user's password: " passwd
- for user in `cat /xie/q.txt`
- do
- id $user &> /dev/null
- if [ $? -eq 0 ]
- then
- echo "user $user is exists"
- else
- useradd $user
- echo "$passwd" | passwd --stdin $user &> /dev/null
- if [ $? -eq 0 ]
- then
- echo "user $user create successfully"
- else
- echo "user $user create failed"
- fi
- fi
- done
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31098809/viewspace-2126162/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31098809/viewspace-2126162/