I just began with Shell script (#!/bin/bash) language. And here is a script:
begin=$(date +"%s")
item='{
"trigram" : "REII",
"pickupReference" : "FRTEST01",
"alertType" : "Overloaded",
"alertStatus" : "Opened",
"alertDetectionDate" : "2020-08-20",
"properties": {"Property4": "13,00 %", "Property6": "45,58 %", "Property20": "35,00 %", "Property22": "18,00" }
},'
for ((i=1;i<=3;i++)); do
item+='
{
"trigram" : "REII",
"pickupReference" : "FRTEST01",
"alertType" : "Overloaded",
"alertStatus" : "Opened",
"alertDetectionDate" : "2020-08-20",
"properties": {"Property4": "13,00 %", "Property6": "45,58 %", "Property20": "35,00 %", "Property22": "18,00" }
},'
done
for ((i=1;i<=2;i++)); do
curl --location --request POST 'https://testurl.com/data' \
--header 'Authorization: Bearer xxxx' \
--header 'Content-Type: application/json' \
--header 'Cookie: BrowserId=XCVJyKw, ...' \
--data-raw '[ '$item
'{"trigram" : "REII",
"pickupReference" : "FRTEST01",
"alertType" : "Overloaded",
"alertStatus" : "Opened",
"alertDetectionDate" : "2020-08-20",
"properties": {"Property4": "13,00 %", "Property6": "45,58 %", "Property20": "35,00 %", "Property22": "18,00" }
} ]';
termin=$(date +"%s")
difftimelps=$(($termin-$begin))
if [ $i -eq 100 ] || [ $i -eq 500 ] || [ $i -eq 1000 ] || [ $i -eq 2000 ] || [ $i -eq 3000 ] || [ $i -eq 4000 ] || [ $i -eq 5000 ]; then
echo "Alert $i - $(($difftimelps / 60)) minutes and $(($difftimelps % 60)) seconds elapsed for Script Execution.">> file_$i.txt
fi
done
$SHELL
I want to add the variable $item to my bash script as shown above but It doesn't work, and I don't know why. Please help!
$item) in orther to use a list of item in the data-raw of my curl script. I've usedShellcheck.combut I didn't sort out. I'm very newbie with shell script. Thx.jqutility to create JSON in shell scripts, rather than doing it by hand. It has methods to allow you to substitute variables into the JSON.