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


在<<鸟哥的私房菜>>  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
就不会报错

转载于:https://my.oschina.net/u/2322146/blog/406230

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值