批量的创建用户,并对每个用户创建不同的密码;


实例一:密码是随机数生成;

#!/bin/bash

rm -f  user.log

for i in `seq -w 5 15`

do

  pass=`echo $RANDOM|md5sum|cut -c 1-8`

  useradd user$i && echo "$pass" | passwd --stdin user$i

  echo -e "user:user$i \t pass:$pass" >>user.log 

done


[root@test02 Shell]# more user.log 

user:user05      pass:aa3905cc

user:user06      pass:68379def

user:user07      pass:6e8d7289

user:user08      pass:ee9adb7c

user:user09      pass:57abd6ab

user:user10      pass:c75b6bf7

user:user11      pass:f1f84021

user:user12      pass:e72d67ba

user:user13      pass:d6f7f0e7

user:user14      pass:490a8500

user:user15      pass:032e1cee


注:删除创建的用户: for i in `seq -w 5 15`; do userdel -r user$i; done


实例二:用mkpasswd生成安全密码;

#!/bin/bash

rm -f  user.log

for i in `seq -w 5 15`

do

  pass=`mkpasswd`

  useradd user$i && echo "$pass" | passwd --stdin user$i

  echo -e "user:user$i \t pass:$pass" >>user.log 

done


[root@test02 Shell]# more user.log 

user:user05      pass:vuVXe76z?

user:user06      pass:Wyxk35xE(

user:user07      pass:Q9eA8p#sb

user:user08      pass:Ar42[Xunx

user:user09      pass:0ZCfaef6{

user:user10      pass:djN3hd#E9

user:user11      pass:mQ9yEzm4>

user:user12      pass:fszK*77oH

user:user13      pass:&y4xp1aUY

user:user14      pass:9Gl7qpSt:

user:user15      pass:33aU|vFik


注:mkpasswd命令  yum install -y expect-5.44.1.15-5.el6_4.x86_64 ;