脚本:
[root@M1-Server ~]# cat useradd.sh
#!/bin/bash. /etc/init.d/functions
for n in $(seq -w 10)
do
passwd=`echo $RANDOM|md5sum|cut -c 1-9`
useradd teddy-$n >&/dev/null && user_status=$?
echo "$passwd"|passwd –stdin teddy-$n >&/dev/null && pass_status=$?if [ $user_status -eq 0 -a $pass_status -eq 0 ];then
action "adduser teddy-$n" /bin/true
echo -e "user:teddy-$n password:$passwd" >>/root/pl_user.txtelse
action "adduser teddy-$n" /bin/fasle
fi
done
执行:
查看结果:
[root@M1-Server ~]# cat pl_user.txt
user:teddy-01 password:97cb9f6ff
user:teddy-02 password:fbcf8d8d1
user:teddy-03 password:d1f0559f2
user:teddy-04 password:398049856
user:teddy-05 password:0837847ec
user:teddy-06 password:ddaaa2528
user:teddy-07 password:3fe51c767
user:teddy-08 password:84abb0bb9
user:teddy-09 password:74e440e32
user:teddy-10 password:90d7c6b43