shell 一种生成随机数的脚本

#!/bin/bash #要修改的配置文件 finance_file="/webdata/opt/local/tomcat-7.0.61-8081/webapps/ops-finance/WEB-INF/classes/properties/finance.properties" order_file="/webdata/opt/loc...

#!/bin/bash

#要修改的配置文件

finance_file="/webdata/opt/local/tomcat-7.0.61-8081/webapps/ops-finance/WEB-INF/classes/properties/finance.properties"

order_file="/webdata/opt/local/tomcat-7.0.61-8085/webapps/ops-order/WEB-INF/classes/properties/order.properties"

goods_file="/webdata/opt/local/tomcat-7.0.61-8082/webapps/ops-goods/WEB-INF/classes/properties/goods.properties"

#生成随机数字序列

random_nums=$(dd if=/dev/urandom bs=1 count=9 2>/dev/null |od -A n -t x4|xargs|sed 's/[0a-zA-Z ]//g')


##生成 1,255之间随机数字

function rand(){  

    min=$1  

    max=$(($2-$min+1))  

    num=$(($RANDOM+$random_nums)) 

    echo  $(($num%$max+$min))  

}  

###随机数从5开始,前四个已经被占用

rnd=$(rand 6 254)


##把生成的随机数补全为3位号码

if [ $rnd -ge 5 -a $rnd -lt 10 ];then

 rnd=00$rnd

 elif [ $rnd -ge 10 -a $rnd -lt 100 ];then

  rnd=0$rnd

 else

rnd=$rnd

fi


#搜索worker_id=4的关键字,然后使用随机生成的worker_id 替换

sed -i "s#worker_id=[0-9]\+#worker_id=$rnd#g" $finance_file $order_file $godds_file

  • 发表于 2017-05-26 13:10
  • 阅读 ( 45 )

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
石天
石天

437 篇文章

作家榜 »

  1. shitian 662 文章
  2. 石天 437 文章
  3. 每天惠23 33 文章
  4. 小A 29 文章