创建5个用户并设置随机密码

                     创建5个用户并设置8位随机密码                           

#!/bin/bash
. /etc/init.d/functions
for i in `seq 5`;do
PASS=`echo $(date +%t%N)$RANDOM |md5sum |cut -c 1-8`
        useradd freddy$i >&/dev/null && USER_STATUS=$?
        echo "$PASS" | passwd freddy$i --stdin >&/dev/null && PASS_STATUS=$?
        if [ $USER_STATUS -eq 0 -a $PASS_STATUS -eq 0 ];then
                action "Useradd freddy$i OK" /bin/true
                echo -e "USER:freddy$i \t PASS:$PASS" >>/tmp/test/user.txt
        else
                action "Useradd freddy$i Fail" /bin/false
                echo "User freddy$i Create Fail.">>/tmp/test/user.txt
        fi
done

 

posted @ 2016-04-25 10:51  唐胜伟  阅读(355)  评论(0编辑  收藏  举报