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详细分析请参考:
https://blog.csdn.net/fen_fen/article/details/108545908



