shell随机生成数

#!/bin/bash
#八位字母和数字的组合
pw1=`openssl rand -base64 8|md5sum|cut -c 1-8`
pw2=`openssl rand -base64 8`
##生成全字符的随机字符串
pw3=`cat /dev/urandom|strings -n 8| head -n 1`

echo $pw1\n
echo $pw2\n
echo $pw3\n
cat <<END> she1.sh
#!/bin/bash 
#批量创建10个系统帐号并设置密码,帐号和密码相同 
for name in `seq -w 10` 
do 
    #非交互式的输入密码 
    useradd linux$name && echo "linux$name" | passwd --stdin linux$name 
done
END
cat <<END>she2.sh
#!/bin/bash 
#批量创建10个系统帐号并设置密码 
rm -f user.log 
for name in `seq -w 10` 
do 
    #非交互式的输入随机密码 
    password=`echo $RANDOM | md5sum | cut -c1-8` 
    #可以使用password=`echo "date $RANDOM" | md5sum | cut -c3-11` 
    #也可以使用password=`penssl rand -base64 8 | md5sum | cut -c1-8` 
    useradd linux$name && echo password | passwd --stdin linux$name 
    echo -e "user=linux$name \t passwd=$password" >> user.log   #保存用户名密码以查阅 
done
END

猜你喜欢

转载自blog.csdn.net/weixin_42562106/article/details/114393664