grep -c prints zero and exits one, so every echo-0 fallback produced a two-line count

This commit is contained in:
Gmer4Lfe
2026-08-06 22:31:50 -04:00
parent 7b2f79e3ac
commit 1b46033584
11 changed files with 32 additions and 22 deletions
+3 -3
View File
@@ -173,7 +173,7 @@ TOTAL_RECLAIMED=0
# ── Step 1 (--all only): remove stopped containers ────────────────────────────
if [[ "$ALL_MODE" == true ]]; then
STOPPED_IDS=$(docker ps -a --filter "status=exited" --filter "status=created" -q 2>/dev/null)
STOPPED_COUNT=$(echo "$STOPPED_IDS" | grep -c . || echo 0)
STOPPED_COUNT=$(echo "$STOPPED_IDS" | grep -c . || true)
if [[ "$STOPPED_COUNT" -eq 0 ]]; then
echo "No stopped containers"
@@ -198,11 +198,11 @@ if [[ "$ALL_MODE" == true ]]; then
# Images not used by any running container
RUNNING_IMAGES=$(docker ps --format "{{.Image}}" 2>/dev/null)
UNUSED_COUNT=$(docker images --format "{{.Repository}}:{{.Tag}}" 2>/dev/null \
| grep -vxF "$RUNNING_IMAGES" | grep -c . || echo 0)
| grep -vxF "$RUNNING_IMAGES" | grep -c . || true)
TARGET_LABEL="$UNUSED_COUNT unused image(s)"
else
DANGLING_IDS=$(docker images -f "dangling=true" -q 2>/dev/null)
UNUSED_COUNT=$(echo "$DANGLING_IDS" | grep -c . || echo 0)
UNUSED_COUNT=$(echo "$DANGLING_IDS" | grep -c . || true)
TARGET_LABEL="$UNUSED_COUNT dangling image(s)"
fi
+1 -1
View File
@@ -212,7 +212,7 @@ echo "━━━ $ICON_SYNC Lidarr Library ━━━"
# fetch when it's stale, and waits out an active rescan before either.
LIDARR_ARTISTS_JSON=$(arr_get_tracked_data "lidarr" "$LIDARR_URL" "$LIDARR_API_KEY" "v1") || { error "Could not fetch Lidarr artists"; exit 1; }
LIDARR_NAMES=$(echo "$LIDARR_ARTISTS_JSON" | jq -r '.[].artistName' 2>/dev/null)
LIDARR_COUNT=$(echo "$LIDARR_NAMES" | grep -c . 2>/dev/null || echo 0)
LIDARR_COUNT=$(echo "$LIDARR_NAMES" | grep -c . 2>/dev/null || true)
log "$LIDARR_COUNT artists already in Lidarr"
_in_lidarr() {
+1 -1
View File
@@ -172,7 +172,7 @@ touch "$DOCKER_WATCHDOG_FAILED_FILE" "$WATCHDOG_CONTAINER_RESTART_LOG" 2>/dev/nu
echo ""
echo "━━━ $ICON_WATCHDOG Skip List Status — $MY_ID ━━━"
SKIP_COUNT=$(grep -c "." "$DOCKER_WATCHDOG_FAILED_FILE" 2>/dev/null || echo 0)
SKIP_COUNT=$(grep -c "." "$DOCKER_WATCHDOG_FAILED_FILE" 2>/dev/null || true)
SKIP_COUNT="${SKIP_COUNT//[^0-9]/}"; SKIP_COUNT="${SKIP_COUNT:-0}"
RESTART_COUNT=$(wc -l < "$WATCHDOG_CONTAINER_RESTART_LOG" 2>/dev/null || echo 0)
RESTART_COUNT="${RESTART_COUNT//[^0-9]/}"; RESTART_COUNT="${RESTART_COUNT:-0}"