#!/bin/bash STATION_A='D7:80:BE:2C:63:BD' STATION_B='F1:CC:C3:0B:7F:5C' STATIONS=($STATION_A $STATION_B) TOKEN=$(curl --insecure --data \ "username=data-api-user&password=jBD0CD1wGOKoTVtC&grant_type=password&client_id=phenode" \ https://phenode-link.com:8443/realms/grafana/protocol/openid-connect/token \ | python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])") #rm -r all-data *.zip for data in "${STATIONS[@]}" do if [ -d $data ] then echo "removing old data directories" ; rm -r $data else echo "nothing to remove" fi ## if data dir exists then remove it echo "downloading data from device with MAC: $data" curl --insecure \ -X POST https://phenode-link.com:2537/devices/$data/all-data/2023-04-10T16:52:21Z \ -H "Authorization: Bearer $TOKEN" \ --output $data.zip unzip $data.zip && mv all-data $data && rm $data.zip && cd $data # remove the null data and replace with 0 sed -i 's/^,/0,/; :a;s/,,/,0,/g;ta' sensor_data.csv # clear the ugly rows from Growing Degree Days awk -F, 'NR==1{print} NR>1 && $2=="0" {gsub(/[)(\]\[]/,"",$0);print}' sensor_data.csv > tmp && mv tmp sensor_data_clean.csv cd ../ done