Shell(18):Shell脚本从文件中读取数据并赋值到命令行中执行

本文介绍如何使用Shell脚本从文件'demo.txt'中读取SM4PerTest的参数(moshi, size, threads, loop),自动化执行并保存结果到'result.txt',提高测试效率。
摘要由CSDN通过智能技术生成

Shell脚步从文件中读取数据并赋值到命令行中执行

前提:本次需要测试性能测试,需要每次手动改动参数进行测试并获取执行结果,但是手动执行太繁琐,故编写shell循环执行。

java com.cipherxxx.crypto.pertest.SM4PerTest gcm 16 1 10000
#后面这几位都是参数:$ms $sz $ths $sloop

解决办法:写1个脚本执行后,执行结果在文件里,直接查看结果即可,以下是脚本。

一、数据列表:demo.txt

{"moshi":"ecb","size":"16","threads":"1","loop":"6000000"}
{"moshi":"ecb","size":"16","threads":"4","loop":"6000000"}
{"moshi":"ecb","size":"16","threads":"8","loop":"3000000"}
{"moshi":"ecb","size":"16","threads":"16","loop":"1600000"}
{"moshi":"ecb","size":"16","threads":"32","loop":"700000"}

二、demo.sh脚本

#!/bin/bash

while read line
do

echo $line>line.txt
#echo $moshi
moshi=$(cat line.txt | sed 's/,/\n/g' | grep "moshi" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g')
ms=$(echo $moshi | tr -d '"')

#echo $size
size=$(cat line.txt | sed 's/,/\n/g' | grep "size" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g')
sz=$(echo $size | tr -d '"')

#echo $ths
threads=$(cat line.txt | sed 's/,/\n/g' | grep "threads" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g')
ths=$(echo $threads | tr -d '"')

#echo $sloop
loop=$(cat line.txt | sed 's/,/\n/g' | grep "loop" | sed 's/:/\n/g' | sed '1d' | sed 's/}//g')
sloop=$(echo $loop | tr -d '"')


#java com.cipherxxx.crypto.pertest.SM4PerTest gcm 1048576 32 100

echo "java com.cipherxxx.crypto.pertest.SM4PerTest $ms $sz $ths $sloop" >> result.txt
echo "moshi: $ms,size: $sz,threads:$ths, sloop: $sloop" >> result.txt
java com.cipherxxx.crypto.pertest.SM4PerTest $ms $sz $ths $sloop>> result.txt           
echo "===============================================">>result.txt

  
done<demo.txt     #从demo.txt获取文件

详细分析请参考:
https://blog.csdn.net/fen_fen/article/details/108545908

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宁宁可可

您的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值