made script more dynamic regarding sensor addition

This commit is contained in:
ikselven 2017-12-16 19:59:40 +01:00
parent 150508b901
commit 1073f0cf90

View file

@ -6,11 +6,12 @@ declare -r TMPFILE="/tmp/sense-data"
curl --silent "$URL" | tr '{[,' "\n" > "$TMPFILE" curl --silent "$URL" | tr '{[,' "\n" > "$TMPFILE"
RAW_VALUES="$(grep -e "title" -e "unit" -e "value" -e "createdAt" "$TMPFILE" | cut -d'"' -f4)" RAW_VALUES="$(grep -e "title" -e "unit" -e "value" -e "createdAt" "$TMPFILE" | cut -d'"' -f4)"
VALUECOUNT=$(grep -c "title" "$TMPFILE")
IFS=$'\n' RAW_VALUES=(${RAW_VALUES}) IFS=$'\n' RAW_VALUES=(${RAW_VALUES})
declare -a VALUES declare -a VALUES
for i in {1..5}; do for i in $(seq 1 $VALUECOUNT); do
raw_index=$(( $i * 4 - 4 )) raw_index=$(( $i * 4 - 4 ))
VALUES[$i]="${RAW_VALUES[$raw_index]}:\t${RAW_VALUES[$raw_index + 2]} ${RAW_VALUES[$raw_index + 1]}\t(as of: ${RAW_VALUES[$raw_index + 3]})" VALUES[$i]="${RAW_VALUES[$raw_index]}:\t${RAW_VALUES[$raw_index + 2]} ${RAW_VALUES[$raw_index + 1]}\t(as of: ${RAW_VALUES[$raw_index + 3]})"
echo -e "${VALUES[$i]}" echo -e "${VALUES[$i]}"