This is the script:
Code: Select all
#!/bin/bash
#Token to authenicate with mindergas.nl
TOKEN=**************************
#fetch meterstand (use jq to parse JSON object correctly)
METERSTAND=`curl -s "http://127.0.0.1:8084/json.htm?type=devices&rid=734" | jq '.result[0].Counter'| tr -d '"'`
#Get OS date, and format it corectly.
NOW=$(date +"%Y-%m-%d")
#Build JSON by hand ;-)
JSON='{ "date":"'$NOW'", "reading":"'$METERSTAND'" }'
#post using curl to API
curl -v -H "Content-Type:application/json" -H "AUTH-TOKEN:$TOKEN" -d "$JSON" https://www.mindergas.nl/api/gas_meter_readings
curl -s "http://127.0.0.1:8084/json.htm?type=devices&rid=734" | jq '.result[0].Counter'| tr -d '"'
The result is: 693.927m3 So it ends with the text m3 and that is the point!
How do I cut those last two characters out of the variable? I just need the value!
Thanks for your hint!