diff --git a/modules/website/500-error-tracker.sh b/modules/website/500-error-tracker.sh index 26bbde2..b0d135e 100755 --- a/modules/website/500-error-tracker.sh +++ b/modules/website/500-error-tracker.sh @@ -717,7 +717,7 @@ done | sort -rn | while IFS='|' read count cause; do # Show example if we have one if [ -n "${cause_examples[$cause]}" ]; then example="${cause_examples[$cause]}" - echo " ${DIM}Example: ${example:0:120}...${NC}" + echo -e " ${DIM}Example: ${example:0:120}...${NC}" fi echo "" done @@ -747,7 +747,9 @@ echo "" if [ -f "$DETAILED_DIAGNOSIS" ] && [ -s "$DETAILED_DIAGNOSIS" ]; then for cause_type in PHP_MEMORY_EXHAUSTED PERMISSION_ERROR HTACCESS_ERROR PHP_FATAL_ERROR PHP_SYNTAX_ERROR MISSING_PHP_FUNCTION DATABASE_CONNECTION FILE_NOT_FOUND PHP_HANDLER_ERROR WP_DEBUG_ERROR DOCROOT_MISSING; do - cause_count=$(grep -c "^${cause_type}|" "$DETAILED_DIAGNOSIS" 2>/dev/null || echo "0") + cause_count=$(grep "^${cause_type}|" "$DETAILED_DIAGNOSIS" 2>/dev/null | wc -l) + cause_count=${cause_count//[^0-9]/} # Remove any non-numeric characters + cause_count=${cause_count:-0} # Default to 0 if empty if [ "$cause_count" -gt 0 ]; then cause_display=$(echo "$cause_type" | tr '_' ' ') @@ -757,25 +759,38 @@ if [ -f "$DETAILED_DIAGNOSIS" ] && [ -s "$DETAILED_DIAGNOSIS" ]; then # Group by unique error pattern (not domain) declare -A issue_domains + # First pass: collect all domains per issue pattern + declare -A pattern_domains_temp + while IFS='|' read -r ctype full_diag; do # Extract just the error part (after domain/) issue_pattern=$(echo "$full_diag" | sed 's/^[^ ]* - //') domain_part=$(echo "$full_diag" | grep -oP '^[^/]+') - # Group domains with same issue - if [ -z "${issue_domains[$issue_pattern]}" ]; then - issue_domains[$issue_pattern]="$domain_part" - else - # Count how many domains (limit to first 5) - count=$(echo "${issue_domains[$issue_pattern]}" | tr ',' '\n' | wc -l) - if [ "$count" -lt 5 ]; then - issue_domains[$issue_pattern]="${issue_domains[$issue_pattern]},$domain_part" - elif [ "$count" -eq 5 ]; then - issue_domains[$issue_pattern]="${issue_domains[$issue_pattern]},..." - fi - fi + # Append to temporary storage + pattern_domains_temp[$issue_pattern]+="$domain_part"$'\n' done < <(grep "^${cause_type}|" "$DETAILED_DIAGNOSIS" 2>/dev/null) + # Second pass: deduplicate and limit to 5 unique domains per pattern + for pattern in "${!pattern_domains_temp[@]}"; do + # Get unique domains, limit to 5 + unique_list=$(echo "${pattern_domains_temp[$pattern]}" | sort -u | head -5 | tr '\n' ',') + # Remove trailing comma + unique_list=${unique_list%,} + + # Count total unique domains + total_unique=$(echo "${pattern_domains_temp[$pattern]}" | sort -u | wc -l) + + # Add "..." if there are more than 5 + if [ "$total_unique" -gt 5 ]; then + unique_list="$unique_list,..." + fi + + issue_domains[$pattern]="$unique_list" + done + + unset pattern_domains_temp + # Display grouped issues shown=0 for pattern in "${!issue_domains[@]}"; do