Rewrite data transfer in bash

This commit is contained in:
Kai S. K. Engelbart 2021-03-11 17:01:25 +01:00
parent 3ba24fb5fc
commit d7b5366bdc
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13

23
transfer-data.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
URL="https://http.bosch-iot-hub.com/telemetry"
TTD="10"
KEY="ZGVmaW5tYUB0MzhiYmNjZDE2MjE3NDViODgxMTk5ZGI2ZWQzZGFiNmE6RGVGaW5NYWNoZW4yMDIwIQ=="
# Build name
NAME=${1#*_}
NAME=${NAME%.*}
# Build body
JSON="{\"$NAME\": ["
while read LINE
do
JSON+="[${LINE%,*}, ${LINE#*,}], "
done < $1
JSON=${JSON::-2}
JSON+=']}'
echo "JSON = $JSON"
# Dispatch curl
curl -X POST $URL -H "accept: */*" -H "hono-ttd: $TTD" -H "Authorization: Basic $KEY" -H "Content-Type: application/json" -d "$JSON"