您的位置:首页 > 运维架构 > Shell

批量生成用户中 --------<<鸟哥的私房菜>>学习日记之一

2015-04-25 00:00 344 查看
在<<鸟哥的私房菜>> 15.1.2中使用addaccount.sh来新建用户

Linux 的版本是Ubuntu 12.10

#!/bin/bash
groupadd myquotagrp
for username in myquota1 myquota2 myquota3 myquota4 quota5
do
useradd -g myquotagrp $username
echo "password" | passwd --stdin $username
done


运行后报错
passwd: unrecognized option '--stdin'
Usage: passwd [options] [LOGIN]

Options:
-a, --all report password status on all accounts
-d, --delete delete the password for the named account
-e, --expire force expire the password for the named account
-h, --help display this help message and exit
-k, --keep-tokens change password only if expired
-i, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-l, --lock lock the password of the named account
-n, --mindays MIN_DAYS set minimum number of days before password
change to MIN_DAYS
-q, --quiet quiet mode
-r, --repository REPOSITORY change password in REPOSITORY repository
-S, --status report password status on the named account
-u, --unlock unlock the password of the named account
-w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
-x, --maxdays MAX_DAYS set maximim number of days before password
change to MAX_DAYS

实验使用的linux版本是ubuntu 12.10 网上查的资料很多人人说 ubuntu 不支持 --stdin 所以使用这种方法批量生成用户 会出问题

所以改成使用chpasswd 来生成密码

代码如下

#!/bin/bash
groupadd myquotagrp
for username in myquota1 myquota2 myquota3 myquota4 quota5
do
useradd -g myquotagrp $username
echo "$username:passwd"|chpasswd
done
就不会报错
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LINUX shell