From 1119f38fd6cd3451a666e146c40a999800040ef3 Mon Sep 17 00:00:00 2001 From: masterdraco Date: Tue, 4 Mar 2025 18:12:11 +0100 Subject: [PATCH] Added enhanced diagnostics for torrent list retrieval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added verbose logging to identify when no torrents are found - Added raw transmission command output logging to troubleshoot connection issues - Improved tracking of torrent ID extraction from command output - Made torrent count always visible, not just in debug mode 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- usr/local/bin/torrent-mover | 9 ++++++- .../lib/torrent-mover/transmission_handler.sh | 26 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/usr/local/bin/torrent-mover b/usr/local/bin/torrent-mover index 5e5fceb..2538ebd 100755 --- a/usr/local/bin/torrent-mover +++ b/usr/local/bin/torrent-mover @@ -118,11 +118,18 @@ main() { log_debug "Getting list of torrents..." local torrent_ids torrent_ids=$(get_torrents) - log_debug "Found $(echo "$torrent_ids" | wc -l) torrents" + log_info "Found $(echo "$torrent_ids" | wc -l) torrents" # Use a regular for loop instead of a pipe to while # to avoid the subshell issue that causes processed_source_dirs to be lost readarray -t torrent_ids_array <<< "$torrent_ids" + + # Print the torrent IDs to debug (always, not just in debug mode) + if [[ ${#torrent_ids_array[@]} -eq 0 ]]; then + log_info "No torrents found to process" + else + log_info "Torrent IDs to process: ${torrent_ids_array[*]}" + fi for id in "${torrent_ids_array[@]}"; do # Skip empty IDs if [[ -z "$id" ]]; then diff --git a/usr/local/lib/torrent-mover/transmission_handler.sh b/usr/local/lib/torrent-mover/transmission_handler.sh index 711c792..66c2d3a 100644 --- a/usr/local/lib/torrent-mover/transmission_handler.sh +++ b/usr/local/lib/torrent-mover/transmission_handler.sh @@ -113,15 +113,33 @@ process_removal() { # get_torrents: Retrieves a list of torrents from Transmission get_torrents() { - local cmd="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n ${TRANSMISSION_USER}:${TRANSMISSION_PASSWORD} -l" - log_debug "Running command: $cmd" + # Log the full command we're about to run, sensitive info redacted for logging + local cmd_display="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n [redacted] -l" + log_info "Running command: $cmd_display" + + # Execute the actual command + local real_cmd="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n ${TRANSMISSION_USER}:${TRANSMISSION_PASSWORD} -l" local output - output=$(retry_command "$cmd" 3 20) + output=$(retry_command "$real_cmd" 3 20) + + # Log the raw output for debugging + log_info "Raw command output:" + log_info "$output" # Extract IDs directly using awk # Skip the header line (NR>1) and print the first column # The IDs are right-aligned with spaces in front, so we need to trim them - echo "$output" | awk 'NR>1 && NF>1 {gsub(/^[ ]+/, "", $1); if ($1 ~ /^[0-9]+$/) print $1}' + local torrent_ids + torrent_ids=$(echo "$output" | awk 'NR>1 && NF>1 {gsub(/^[ ]+/, "", $1); if ($1 ~ /^[0-9]+$/) print $1}') + + # Check if we found any torrents + if [[ -z "$torrent_ids" ]]; then + log_info "No torrent IDs found in transmission output" + else + log_info "Found torrent IDs: $torrent_ids" + fi + + echo "$torrent_ids" } # get_torrent_info: Gets detailed info for a specific torrent