Created
August 27, 2025 08:37
-
-
Save johnybradshaw/cb8d7027f52993097dcca1cc13f92aa0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Cleanup dangling resources | |
| # Nodebalancers | |
| linode-cli nodebalancers list --format id,label --json | jq -r '.[] | "\(.id) \(.label)"' | while read -r id label; do | |
| all_down=true | |
| for config_id in $(linode-cli nodebalancers configs-list "$id" --format id --json | jq -r '.[].id'); do | |
| if ! linode-cli nodebalancers nodes-list "$id" "$config_id" --format status --json | jq -e 'all(.[]; .status == "DOWN")' > /dev/null; then | |
| all_down=false | |
| break | |
| fi | |
| done | |
| if [ "$all_down" = true ]; then | |
| echo "NodeBalancer '$label' (ID: $id) has all backend nodes DOWN." | |
| # Uncomment the next line to actually delete them | |
| linode-cli nodebalancers delete "$id" | |
| fi | |
| done | |
| # Unused Volumes | |
| linode-cli volumes list --json | jq -r '.[] | select(.linode_id == null) | .id' | xargs -I {} linode-cli volumes delete {} | |
| # Firewalls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment