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() { get_disk_health() {
echo -e "\n${GREEN}=== Disk Health Status ===${NC}" echo -e "\n${GREEN}=== Disk Health Status ===${NC}"
if command -v smartctl >/dev/null 2>&1; then 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:" echo -e "\nChecking /dev/$disk:"
smartctl -H /dev/$disk smartctl -H "/dev/$disk"
done done < <(lsblk -d -o name | grep -E '^sd|^nvme')
else else
log_message warn "smartctl not found. Install smartmontools for disk health monitoring" log_message warn "smartctl not found. Install smartmontools for disk health monitoring"
fi fi
@@ -480,12 +481,13 @@ quick_health_check() {
# Disk health (quick) # Disk health (quick)
echo -e "\n${GREEN}=== Disk Health Summary ===${NC}" echo -e "\n${GREEN}=== Disk Health Summary ===${NC}"
if command -v smartctl >/dev/null 2>&1; then 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
health=$(smartctl -H /dev/$disk 2>/dev/null | grep -i "health" | awk -F: '{print $2}' | xargs) [[ -z "$disk" ]] && continue
health=$(smartctl -H "/dev/$disk" 2>/dev/null | grep -i "health" | awk -F: '{print $2}' | xargs)
if [[ -n "$health" ]]; then if [[ -n "$health" ]]; then
echo -e "/dev/$disk: $health" echo -e "/dev/$disk: $health"
fi fi
done done < <(lsblk -d -o name | grep -E '^sd|^nvme')
fi fi
# Node Exporter # Node Exporter