一系列参数存于文本文件,需在LINUX下循环读取,之后以此参数进行CURL远程API调用,同时需记录每次CURL的总时间
参数文件,test1.json
{"ADDRESS_FREE":"XXX","NAME":{"SURNAME":"XXX","FIRST_NAME":"XXX"}}
{"ADDRESS_FREE":"XXX","NAME":{"SURNAME":"XXX","FIRST_NAME":"XXX"}}
{"ADDRESS_FREE":"XXX","NAME":{"SURNAME":"XXX","FIRST_NAME":"XXX"}}
test1.sh
#! /bin/bash
RESULT_FILE="result.csv"
echo "" > $RESULT_FILE
i=1
while read line || [[ "$line" ]] #In case the file has an incomplete (missing newline) last line, you could use this alternative:
do
echo "$i"
printf "$i;$line;" >> $RESULT_FILE
curl -w %{time_total} -o /dev/null -X POST -H "Content-Type:application/json" -d "$line" http://ip:port >> $RESULT_FILE
#printf "\n\r" >> $RESULT_FILE
echo "" >> $RESULT_FILE
#i=$(( $i + 1 ))
(( i++ ))
done < test1.json
Reference:
https://stackoverflow.com/questions/30988586/creating-an-array-from-a-text-file-in-bash