Skip to content

Instantly share code, notes, and snippets.

@mrjk
Last active April 23, 2026 13:35
Show Gist options
  • Select an option

  • Save mrjk/8a74b4597716bebea2a0b965c06b54ff to your computer and use it in GitHub Desktop.

Select an option

Save mrjk/8a74b4597716bebea2a0b965c06b54ff to your computer and use it in GitHub Desktop.
Report health status for all disks with SMART
#!/bin/bash
# This script reports the most common CPU flags to pay attention.
# Usage:
# curl https://gist.githubusercontent.com/mrjk/8a74b4597716bebea2a0b965c06b54ff/raw/26cd0e43d1694bf40cb5f2935ff88f36a0f77a81/report-disk-health.sh | bash
report_smart() {
command -v smartctl >/dev/null || {
echo "ERROR: Missing smartctl command, try to install smartctl or smartmontools"
return 1
}
local GREEN='\033[0;32m'
local YELLOW='\033[1;33m'
local RED='\033[0;31m'
local NC='\033[0m'
echo "=== SMART Disk Health Check ==="
for disk in $(lsblk -d -n -o NAME | grep -E "^sd|^hd|^nvme"); do
dev="/dev/$disk"
# Get the real indicators of disk failure
raw=$(sudo smartctl -A $dev 2>/dev/null)
reallocated=$(echo "$raw" | grep -i "Reallocated_Sector_Ct" | awk '{print $10}')
pending=$(echo "$raw" | grep -i "Current_Pending_Sector" | awk '{print $10}')
uncorr=$(echo "$raw" | grep -i "Offline_Uncorrectable" | awk '{print $10}')
# Default to 0 if not found
reallocated=${reallocated:-0}
pending=${pending:-0}
uncorr=${uncorr:-0}
if [ "$reallocated" -gt 0 ] || [ "$pending" -gt 0 ] || [ "$uncorr" -gt 0 ]; then
echo -e "${RED}[FAILING]${NC} $dev — reallocated=$reallocated pending=$pending uncorrectable=$uncorr"
else
echo -e "${GREEN}[OK] ${NC} $dev — reallocated=$reallocated pending=$pending uncorrectable=$uncorr"
fi
done
}
report_smart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment