#!/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
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!