Added extensive diagnostic logging for Transmission connectivity
- Completely rewrote retry_command to show detailed output on each attempt - Added direct Transmission connectivity test before using retry logic - Added line-by-line analysis of Transmission command output - Added test fallback ID in dry-run mode to verify downstream processing - Added connection parameter logging (with redacted password) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
1119f38fd6
commit
91106a244c
@ -161,44 +161,59 @@ retry_command() {
|
||||
local wait_time="${3:-10}" # Default to 10 seconds wait between attempts
|
||||
local attempt=1
|
||||
local exit_code=0
|
||||
local error_output=""
|
||||
local command_output=""
|
||||
|
||||
# Create a temporary file for capturing error output
|
||||
local error_file
|
||||
error_file=$(mktemp)
|
||||
# Create a temporary file for capturing output
|
||||
local output_file
|
||||
output_file=$(mktemp)
|
||||
|
||||
# Use a more verbose logging for this command - always log, not just in debug mode
|
||||
log_info "Executing command: $cmd"
|
||||
|
||||
while (( attempt <= max_attempts )); do
|
||||
log_debug "Attempt $attempt of $max_attempts: $cmd"
|
||||
log_info "Attempt $attempt of $max_attempts: $cmd"
|
||||
|
||||
# Execute command and capture both exit code and stderr
|
||||
error_output=$( { eval "$cmd"; exit_code=$?; } 2>&1 > >(tee /dev/stderr) )
|
||||
# Execute command directly and capture output and exit code
|
||||
command_output=$(eval "$cmd" 2>&1)
|
||||
exit_code=$?
|
||||
echo "$command_output" > "${output_file}"
|
||||
|
||||
# Always log the first 10 lines of output
|
||||
log_info "Command output (first 10 lines):"
|
||||
head -n 10 "${output_file}" | while IFS= read -r line; do
|
||||
log_info " > $line"
|
||||
done
|
||||
|
||||
if [[ ${exit_code} -eq 0 ]]; then
|
||||
log_debug "Command succeeded on attempt $attempt"
|
||||
rm -f "${error_file}"
|
||||
log_info "Command succeeded on attempt $attempt"
|
||||
rm -f "${output_file}"
|
||||
echo "$command_output"
|
||||
return 0
|
||||
else
|
||||
# Log detailed error information
|
||||
echo "${error_output}" > "${error_file}"
|
||||
log_warn "Command failed (attempt $attempt, exit code: ${exit_code})"
|
||||
log_debug "Error details: $(head -n 5 "${error_file}")"
|
||||
|
||||
if (( attempt == max_attempts )); then
|
||||
log_error "Maximum attempts reached for command, last exit code: ${exit_code}"
|
||||
log_error "Last error output: $(head -n 10 "${error_file}")"
|
||||
rm -f "${error_file}"
|
||||
log_error "Last error output (first 10 lines):"
|
||||
head -n 10 "${output_file}" | while IFS= read -r line; do
|
||||
log_error " > $line"
|
||||
done
|
||||
rm -f "${output_file}"
|
||||
echo "$command_output"
|
||||
return ${exit_code}
|
||||
fi
|
||||
|
||||
# Exponential backoff - wait longer for each successive attempt
|
||||
local adjusted_wait=$((wait_time * attempt))
|
||||
log_debug "Waiting ${adjusted_wait} seconds before retry"
|
||||
log_info "Waiting ${adjusted_wait} seconds before retry"
|
||||
sleep ${adjusted_wait}
|
||||
(( attempt++ ))
|
||||
fi
|
||||
done
|
||||
|
||||
rm -f "${error_file}"
|
||||
rm -f "${output_file}"
|
||||
echo "$command_output"
|
||||
return 1
|
||||
}
|
||||
|
||||
|
@ -113,33 +113,84 @@ process_removal() {
|
||||
|
||||
# get_torrents: Retrieves a list of torrents from Transmission
|
||||
get_torrents() {
|
||||
# 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"
|
||||
# Log connection parameters (redacted password)
|
||||
log_info "Transmission connection parameters:"
|
||||
log_info " IP: ${TRANSMISSION_IP}:${TRANSMISSION_PORT}"
|
||||
log_info " Username: ${TRANSMISSION_USER}"
|
||||
log_info " Password: [redacted]"
|
||||
|
||||
# Execute the actual command
|
||||
# Try a direct command without using retry_command to get clearer error messages
|
||||
log_info "Direct transmission-remote access test:"
|
||||
local test_output
|
||||
test_output=$(transmission-remote "${TRANSMISSION_IP}:${TRANSMISSION_PORT}" -n "${TRANSMISSION_USER}:${TRANSMISSION_PASSWORD}" -l 2>&1)
|
||||
local test_exit=$?
|
||||
if [[ $test_exit -ne 0 ]]; then
|
||||
log_error "Direct transmission-remote test failed with exit code: $test_exit"
|
||||
log_error "Error output: $test_output"
|
||||
# Continue anyway to see retry attempt logs
|
||||
else
|
||||
log_info "Direct transmission-remote test succeeded"
|
||||
fi
|
||||
|
||||
# Execute the actual command with retries
|
||||
local real_cmd="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n ${TRANSMISSION_USER}:${TRANSMISSION_PASSWORD} -l"
|
||||
local output
|
||||
output=$(retry_command "$real_cmd" 3 20)
|
||||
|
||||
# Log the raw output for debugging
|
||||
log_info "Raw command output:"
|
||||
log_info "$output"
|
||||
# Line-by-line raw output inspection (debugging)
|
||||
log_info "Raw command output detailed analysis:"
|
||||
if [[ -z "$output" ]]; then
|
||||
log_error "Command produced EMPTY output"
|
||||
else
|
||||
log_info "Output length: $(echo "$output" | wc -l) lines"
|
||||
echo "$output" | while IFS= read -r line; do
|
||||
log_info " LINE: '$line'"
|
||||
done
|
||||
fi
|
||||
|
||||
# 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
|
||||
# Extract IDs directly using awk with detailed debugging
|
||||
log_info "Extracting torrent IDs from output..."
|
||||
local line_num=0
|
||||
local found_ids=0
|
||||
echo "$output" | while IFS= read -r line; do
|
||||
line_num=$((line_num + 1))
|
||||
# Skip header line
|
||||
if [[ $line_num -eq 1 ]]; then
|
||||
log_info " Skipping header: '$line'"
|
||||
continue
|
||||
fi
|
||||
# Check for torrent ID in first column
|
||||
local potential_id
|
||||
potential_id=$(echo "$line" | awk '{gsub(/^[ ]+/, "", $1); print $1}')
|
||||
log_info " Line $line_num: potential ID '$potential_id'"
|
||||
if [[ "$potential_id" =~ ^[0-9]+$ ]]; then
|
||||
log_info " Found valid ID: $potential_id"
|
||||
found_ids=$((found_ids + 1))
|
||||
echo "$potential_id"
|
||||
else
|
||||
log_info " Not a valid ID: '$potential_id'"
|
||||
fi
|
||||
done | tee /tmp/torrent_ids.txt
|
||||
|
||||
# Read back the file to get around pipe subshell issues
|
||||
local torrent_ids
|
||||
torrent_ids=$(echo "$output" | awk 'NR>1 && NF>1 {gsub(/^[ ]+/, "", $1); if ($1 ~ /^[0-9]+$/) print $1}')
|
||||
torrent_ids=$(cat /tmp/torrent_ids.txt)
|
||||
rm -f /tmp/torrent_ids.txt
|
||||
|
||||
# Check if we found any torrents
|
||||
if [[ -z "$torrent_ids" ]]; then
|
||||
log_info "No torrent IDs found in transmission output"
|
||||
log_error "NO TORRENT IDs FOUND in transmission output"
|
||||
else
|
||||
log_info "Found torrent IDs: $torrent_ids"
|
||||
fi
|
||||
|
||||
echo "$torrent_ids"
|
||||
# Fallback to hardcoded ID for testing if nothing found
|
||||
if [[ -z "$torrent_ids" && "${DRY_RUN}" -eq 1 ]]; then
|
||||
log_info "DRY RUN MODE: Adding test torrent ID 1 for debugging"
|
||||
echo "1"
|
||||
else
|
||||
echo "$torrent_ids"
|
||||
fi
|
||||
}
|
||||
|
||||
# get_torrent_info: Gets detailed info for a specific torrent
|
||||
|
Loading…
x
Reference in New Issue
Block a user