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
+7 -7
View File
@@ -283,7 +283,7 @@ if [[ -n "$SLSKD_URL" ]] && [[ -n "$SLSKD_API_KEY" ]] && [[ "$SLSKD_CONNECTED" =
IDS=$(echo "$SEARCHES" | tr '{' '\n' | \
grep '"isComplete":true' | grep '"searchText":' | \
grep -o '"id":"[^"]*"' | sed 's/"id":"//;s/"//')
COUNT=$(echo "$IDS" | grep -c . 2>/dev/null || echo 0)
COUNT=$(echo "$IDS" | grep -c . 2>/dev/null || true)
COUNT="${COUNT//[^0-9]/}"; COUNT="${COUNT:-0}"
if [[ "$COUNT" -eq 0 ]]; then
@@ -339,7 +339,7 @@ if [[ -n "$SLSKD_URL" ]] && [[ -n "$SLSKD_API_KEY" ]] && [[ "$SLSKD_CONNECTED" =
if [[ -z "$USERNAMES" ]]; then
success "No transfer records found ✅"
else
USER_COUNT=$(echo "$USERNAMES" | grep -c . 2>/dev/null || echo 0)
USER_COUNT=$(echo "$USERNAMES" | grep -c . 2>/dev/null || true)
log "Found $USER_COUNT user(s) with transfer records"
SUCCESS=0; SKIPPED=0; FAIL=0
while IFS= read -r USER; do
@@ -416,7 +416,7 @@ if [[ -n "$SLSKD_FAILED_IMPORTS_DIR" ]]; then
else
OLD_IMPORTS=$(find "$SLSKD_FAILED_IMPORTS_DIR" \
-mindepth 1 -maxdepth 1 -mtime +"${DOWNLOADER_RETENTION_DAYS}")
IMPORT_COUNT=$(echo "$OLD_IMPORTS" | grep -c . 2>/dev/null || echo 0)
IMPORT_COUNT=$(echo "$OLD_IMPORTS" | grep -c . 2>/dev/null || true)
IMPORT_COUNT="${IMPORT_COUNT//[^0-9]/}"; IMPORT_COUNT="${IMPORT_COUNT:-0}"
if [[ "$IMPORT_COUNT" -eq 0 ]]; then
@@ -459,7 +459,7 @@ if [[ -n "$SABNZBD_URL" ]] && [[ -n "$SABNZBD_API_KEY" ]]; then
if [[ -z "$COMPLETED_IDS" ]]; then
success "No completed history found ✅"
else
HIST_TOTAL=$(echo "$COMPLETED_IDS" | grep -c . 2>/dev/null || echo 0)
HIST_TOTAL=$(echo "$COMPLETED_IDS" | grep -c . 2>/dev/null || true)
log "Found $HIST_TOTAL completed history entries"
DELETED=0; SKIPPED=0
while IFS= read -r NZO_ID; do
@@ -507,7 +507,7 @@ if [[ -n "$SABNZBD_URL" ]] && [[ -n "$SABNZBD_API_KEY" ]]; then
if [[ -z "$FAILED_IDS" ]]; then
success "No failed history found ✅"
else
FAILED_TOTAL=$(echo "$FAILED_IDS" | grep -c . 2>/dev/null || echo 0)
FAILED_TOTAL=$(echo "$FAILED_IDS" | grep -c . 2>/dev/null || true)
log "Found $FAILED_TOTAL failed history entries"
DELETED=0; SKIPPED=0
while IFS= read -r NZO_ID; do
@@ -557,7 +557,7 @@ if [[ -n "$SABNZBD_URL" ]] && [[ -n "$SABNZBD_API_KEY" ]]; then
if [[ -z "$STALLED_IDS" ]]; then
success "No stalled queue items found ✅"
else
QUEUE_TOTAL=$(echo "$STALLED_IDS" | grep -c . 2>/dev/null || echo 0)
QUEUE_TOTAL=$(echo "$STALLED_IDS" | grep -c . 2>/dev/null || true)
log "Found $QUEUE_TOTAL queue item(s) — checking status"
DELETED=0; SKIPPED=0
while IFS= read -r NZO_ID; do
@@ -618,7 +618,7 @@ if [[ -n "$QBIT_URL" ]] && [[ -n "$QBIT_USERNAME" ]]; then
-H "Cookie: $QBIT_COOKIE" 2>/dev/null)
NOW=$(date +%s)
TORRENT_TOTAL=$(echo "$TORRENTS" | tr '}' '\n' | grep -c '"hash"' 2>/dev/null || echo 0)
TORRENT_TOTAL=$(echo "$TORRENTS" | tr '}' '\n' | grep -c '"hash"' 2>/dev/null || true)
log "Found $TORRENT_TOTAL torrent(s) — applying age/ratio filter"
DELETED=0; SKIPPED=0