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 wait_time="${3:-10}" # Default to 10 seconds wait between attempts
|
||||||
local attempt=1
|
local attempt=1
|
||||||
local exit_code=0
|
local exit_code=0
|
||||||
local error_output=""
|
local command_output=""
|
||||||
|
|
||||||
# Create a temporary file for capturing error output
|
# Create a temporary file for capturing output
|
||||||
local error_file
|
local output_file
|
||||||
error_file=$(mktemp)
|
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
|
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
|
# Execute command directly and capture output and exit code
|
||||||
error_output=$( { eval "$cmd"; exit_code=$?; } 2>&1 > >(tee /dev/stderr) )
|
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
|
if [[ ${exit_code} -eq 0 ]]; then
|
||||||
log_debug "Command succeeded on attempt $attempt"
|
log_info "Command succeeded on attempt $attempt"
|
||||||
rm -f "${error_file}"
|
rm -f "${output_file}"
|
||||||
|
echo "$command_output"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
# Log detailed error information
|
# Log detailed error information
|
||||||
echo "${error_output}" > "${error_file}"
|
|
||||||
log_warn "Command failed (attempt $attempt, exit code: ${exit_code})"
|
log_warn "Command failed (attempt $attempt, exit code: ${exit_code})"
|
||||||
log_debug "Error details: $(head -n 5 "${error_file}")"
|
|
||||||
|
|
||||||
if (( attempt == max_attempts )); then
|
if (( attempt == max_attempts )); then
|
||||||
log_error "Maximum attempts reached for command, last exit code: ${exit_code}"
|
log_error "Maximum attempts reached for command, last exit code: ${exit_code}"
|
||||||
log_error "Last error output: $(head -n 10 "${error_file}")"
|
log_error "Last error output (first 10 lines):"
|
||||||
rm -f "${error_file}"
|
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}
|
return ${exit_code}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Exponential backoff - wait longer for each successive attempt
|
# Exponential backoff - wait longer for each successive attempt
|
||||||
local adjusted_wait=$((wait_time * 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}
|
sleep ${adjusted_wait}
|
||||||
(( attempt++ ))
|
(( attempt++ ))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
rm -f "${error_file}"
|
rm -f "${output_file}"
|
||||||
|
echo "$command_output"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,33 +113,84 @@ process_removal() {
|
|||||||
|
|
||||||
# get_torrents: Retrieves a list of torrents from Transmission
|
# get_torrents: Retrieves a list of torrents from Transmission
|
||||||
get_torrents() {
|
get_torrents() {
|
||||||
# Log the full command we're about to run, sensitive info redacted for logging
|
# Log connection parameters (redacted password)
|
||||||
local cmd_display="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n [redacted] -l"
|
log_info "Transmission connection parameters:"
|
||||||
log_info "Running command: $cmd_display"
|
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 real_cmd="transmission-remote ${TRANSMISSION_IP}:${TRANSMISSION_PORT} -n ${TRANSMISSION_USER}:${TRANSMISSION_PASSWORD} -l"
|
||||||
local output
|
local output
|
||||||
output=$(retry_command "$real_cmd" 3 20)
|
output=$(retry_command "$real_cmd" 3 20)
|
||||||
|
|
||||||
# Log the raw output for debugging
|
# Line-by-line raw output inspection (debugging)
|
||||||
log_info "Raw command output:"
|
log_info "Raw command output detailed analysis:"
|
||||||
log_info "$output"
|
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
|
# Extract IDs directly using awk with detailed debugging
|
||||||
# Skip the header line (NR>1) and print the first column
|
log_info "Extracting torrent IDs from output..."
|
||||||
# The IDs are right-aligned with spaces in front, so we need to trim them
|
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
|
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
|
# Check if we found any torrents
|
||||||
if [[ -z "$torrent_ids" ]]; then
|
if [[ -z "$torrent_ids" ]]; then
|
||||||
log_info "No torrent IDs found in transmission output"
|
log_error "NO TORRENT IDs FOUND in transmission output"
|
||||||
else
|
else
|
||||||
log_info "Found torrent IDs: $torrent_ids"
|
log_info "Found torrent IDs: $torrent_ids"
|
||||||
fi
|
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
|
# get_torrent_info: Gets detailed info for a specific torrent
|
||||||
|
Loading…
x
Reference in New Issue
Block a user