批量添加用户,并设置8位随机密码(禁止使用for,while等循环)

原文链接: http://www.cnblogs.com/linyushuan/p/9886595.html

批量添加用户,并设置8位随机密码(禁止使用for,while等循环)

 

创建用户:

[root@lin lin]# echo oldboy{01..05}|xargs -n1

oldboy01

oldboy02

oldboy03

oldboy04

oldboy05

[root@lin lin]# echo oldboy{01..05}|xargs -n1|awk '{print "useradd "$NF}'

useradd oldboy01

useradd oldboy02

useradd oldboy03

useradd oldboy04

useradd oldboy05

交给bash执行

[root@lin lin]# echo oldboy{01..05}|xargs -n1|awk '{print "useradd "$NF}'|bash

 

设置随机密码

方法1:

[root@lin lin]# echo oldboy{01..05}:$(echo $RANDOM|md5sum|cut -c 1-8)|xargs -n1

oldboy01:2ea44fb5

oldboy02:24d3d6ab

oldboy03:d524fdff

oldboy04:92e6c1e7

oldboy05:9e6830d8

 

方法2:

[root@lin lin]# echo oldboy{01..05}:$((RANDOM +10000000))|xargs -n1

oldboy01:10029728

oldboy02:10003967

oldboy03:10029427

oldboy04:10021946

oldboy05:10020909

 

重定向到文件

[root@lin lin]# echo oldboy{01..05}:$((RANDOM +10000000))|xargs -n1>oldboypwd.txt

[root@lin lin]# cat oldboypwd.txt

oldboy01:10027086

oldboy02:10023644

oldboy03:10016532

oldboy04:10017825

oldboy05:10027238

 

修改密码

[root@lin lin]# chpasswd < oldboypwd.txt

 

 

方法3:

[root@lin tmp]# echo a{01..05}|xargs -n1|sed -r 's#(.*)#useradd \1;pass=$(echo $RANDOM|md5sum|cut -c 1-8);echo "$pass"|passwd --stdin \1;echo "\1 $pass" >> /tmp/user1.txt#g'|bash

 

转载于:https://www.cnblogs.com/linyushuan/p/9886595.html

你可能感兴趣的:(批量添加用户,并设置8位随机密码(禁止使用for,while等循环))