您的位置:首页 > 运维架构 > Shell

linux shell 生成随机字符串脚本

2015-05-30 22:18 567 查看
脚本作用:

生成特定长度的字符串,只包含数字或者大小写字母。

count定义字符串的长度

number定义字符串的数目

line定义生成多少个随机字符串,如果number值很大,相应的将line值调大。

由于pv1中的字符串长度不是固定的,所以需要经过一个for循环进行字符串筛选。

以下是脚本命令:

#!/bin/bash



count=6


line=100

number=10

touch /root/pv1.txt

cat /dev/urandom |sed 's/[^a-zA-Z0-9]//g'|strings -n $count |head -n $line|grep -i '^[a-z]'|sort > /root/pv1.txt



touch /root/pv$count.txt

for i in `cat /root/pv1.txt`;do

[ ${#i} -eq $count ] && echo $i >>pv2txt


done

touch /root/password$number.txt

head -10 /root/pv2.txt > /root/password$number.txt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: