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.

#17

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 10:44:43 -05:00
parent e1dac4c08c
commit c25e3ccc76

View File

@@ -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