Following up from my previous question

Streaming my UPS metrics for graphical viewing in bash

#!/usr/bin/env bash

[ -v METRICS_CHECK ] && set -x


for index in "${!UPS_PROPS[@]}"
    value=$(/sbin/apcaccess -up "${UPS_PROPS[$index]}")
    field=$((index + 1))
    if [ "$field" -eq 2 ]
        # bc required for floating point arithmetic
        value=$(echo "$value * 6" | bc)  # 600 Watt * load percent
    PARAM=$(printf "field%d==%s" "$field" "$value")

/usr/local/bin/http "$API_URL" ${API_PARAMS[@]}


  • Collects data for different metrics supported by apcaccess
  • Use a variable check for enabling debug mode
  • Split parameters sent to API URL into a different array
  • Move away from curl to use httpie
  • Custom computation for certain attributes

The shellcheck passes everything except the unquoted ${API_PARAMS[@]} in the last line. I am not sure that httpie would work if I quote that and pass it as a single argument.

Charts for viewing pleasure (last 600 minutes data from the time post was created):

  1. Input line voltage


  2. Load (in wattage) on the UPS


  3. Battery time left for the UPS


Click the images to get live charts.

  • 1
    \$\begingroup\$ Can you edit the titles on those charts, so they are not all "voltage"? (I know that's not part of the code, so this question isn't a review). \$\endgroup\$ Apr 17, 2018 at 7:50

1 Answer 1


Quoting - you need double-quotes on the last line: it should be "${API_PARAMS[@]}" (remember that the [@] makes the shell expand it into multiple words, so it won't be seen by your http program as just one).

Instead of if [ "$field" -eq 2 ], it's clearer to compare the field name. That will help if you change the properties list in future. It may help to create a variable:

value=$(/sbin/apcaccess -up "$propname")
if [ "$propname" = LOADPCT ]

We can supply standard input from a string without needing an echo process, by using <<< redirection:

    # bc required for floating point arithmetic
    value=$(<<<"$value * 6" bc)  # 600 Watt * load percent

We can make the array 1-based, and avoid the need to have $field different from $index:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.