Skip to content

Instantly share code, notes, and snippets.

@richard-scott
Created June 25, 2020 14:58
Show Gist options
  • Save richard-scott/a44936c50a9b50bb4c426ef35570fec5 to your computer and use it in GitHub Desktop.
Save richard-scott/a44936c50a9b50bb4c426ef35570fec5 to your computer and use it in GitHub Desktop.

Revisions

  1. @artkrz artkrz revised this gist Feb 19, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion hass_influx_drop_mesurments.sh
    Original file line number Diff line number Diff line change
    @@ -32,5 +32,5 @@ then
    fi

    else
    echo "Did not fount any measurements matching your query. Exiting."
    echo "Did not found any measurements matching your query. Exiting."
    fi
  2. @artkrz artkrz revised this gist Jan 27, 2020. No changes.
  3. @artkrz artkrz created this gist Jan 27, 2020.
    36 changes: 36 additions & 0 deletions hass_influx_drop_mesurments.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/bin/bash

    host=localhost
    db='home_assistant'
    measurements=$1

    measurements=($(influx --host $host --execute 'show measurements' --database=$db | grep "$1"))

    if (( ${#measurements[@]} ))
    then

    echo "Found following measurements: "
    echo

    for m in ${measurements[*]}
    do
    echo " - $m"
    done

    echo
    read -p "Are you sure you want to drop these from database? (y/N)" -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
    for m in ${measurements[*]}
    do
    echo "Dropping $m..."
    influx --host $host --database=$db --execute "drop measurement \"$m\";"
    done
    else
    echo "OK, leaving it alone..."
    fi

    else
    echo "Did not fount any measurements matching your query. Exiting."
    fi