From c25e3ccc768ab7ad4c6510dddc82c6c00e207f67 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Feb 2026 10:44:43 -0500 Subject: [PATCH] Fix variable quoting in disk iteration loops Replace unsafe for loops with properly quoted while loops when iterating over disk devices. This prevents word splitting issues with device names containing special characters. https://code.lotusguild.org/LotusGuild/proxDoc/issues/17 Co-Authored-By: Claude Opus 4.5 --- proxDoc.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/proxDoc.sh b/proxDoc.sh index e7c00ef..551aeca 100755 --- a/proxDoc.sh +++ b/proxDoc.sh @@ -102,10 +102,11 @@ get_temp_info() { get_disk_health() { echo -e "\n${GREEN}=== Disk Health Status ===${NC}" if command -v smartctl >/dev/null 2>&1; then - for disk in $(lsblk -d -o name | grep -E '^sd|^nvme'); do + while IFS= read -r disk; do + [[ -z "$disk" ]] && continue echo -e "\nChecking /dev/$disk:" - smartctl -H /dev/$disk - done + smartctl -H "/dev/$disk" + done < <(lsblk -d -o name | grep -E '^sd|^nvme') else log_message warn "smartctl not found. Install smartmontools for disk health monitoring" fi @@ -480,12 +481,13 @@ quick_health_check() { # Disk health (quick) echo -e "\n${GREEN}=== Disk Health Summary ===${NC}" if command -v smartctl >/dev/null 2>&1; then - for disk in $(lsblk -d -o name | grep -E '^sd|^nvme'); do - health=$(smartctl -H /dev/$disk 2>/dev/null | grep -i "health" | awk -F: '{print $2}' | xargs) + while IFS= read -r disk; do + [[ -z "$disk" ]] && continue + health=$(smartctl -H "/dev/$disk" 2>/dev/null | grep -i "health" | awk -F: '{print $2}' | xargs) if [[ -n "$health" ]]; then echo -e "/dev/$disk: $health" fi - done + done < <(lsblk -d -o name | grep -E '^sd|^nvme') fi # Node Exporter