I am storing 2 values in my TMP location: {time_total} and {http_code}
I want to add an if-then condition that checks for the status. If it is anything other than 100, I want it to print out a line saying "something is wrong". But display nothing if the value is equal to 100.
echo getInfo >> $SAVE_TO
for i in "${LB[@]}"
do
TMP=$(curl -X GET -sS -w "%{time_total},%{http_code}\n" -H "UNAME:
$USER" -H "UPASS: $PWD" -H "Content-Type: application/json" -d '{"propertytosearch":"systemUserName", "systemUserName":"XXXXXXX"}' https://$i/ws/rest/v2/getInfo -o /dev/null)
echo ,$i,$TMP >> $SAVE_TO
done
if [[ $http_code != $200 ]]
then
echo "something wrong with $i"
fi
TMP Output:
1.207,100
If I remove %{time} and only use %{status}, the if-then command works. How would I do it for 2 input values?
I don't necessarily need to check for {time}, but if required, I can have an if condition for time that checks for anything greater than 4.000. It can have the same echo "something is wrong".
"$100"should use use100?SAVE_TOsupposed to demonstrate why you want to keepTMP? Why notecho ",$i,$time,$status"if you want to reconstruct the items?>>anythingrepeated in your script is a code smell -- much more efficient to just open a file once and reuse that open handle whenever you want to write another line instead of re-opening it over and over.