Last active
November 22, 2022 14:13
-
-
Save basebandit/f591f5b68f3df9b5170f8955248c85ee to your computer and use it in GitHub Desktop.
This file contains 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 | |
function delete_container() { | |
if ! which "lxc" >/dev/null 2>&1; then | |
echo "lxc is not installed" | |
fi | |
OUT=$(lxc list -c n --format=json | jq 'length') | |
if [ "$OUT" -lt 1 ]; then | |
echo "No containers found" | |
fi | |
OUT=$(lxc stop --all 2>&1) | |
check_exit_code $? | |
containers=$(lxc list --format=json | jq -r '.[] | .name') | |
for container in $containers; do | |
echo "Removing container ${container}" | |
lxc delete "$container" 2>&1 | |
check_exit_code $? | |
done | |
} | |
function check_exit_code() { | |
status=$1 | |
if [ $status -ne 0 ]; then | |
echo "{$OUT}" | |
fi | |
} | |
delete_container |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment