Created
April 13, 2026 14:25
-
-
Save koola/7ea530aa895953adc776d1a15fb26346 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 1. Add /usr/local/sbin to the current script's PATH | |
| export PATH="/usr/local/sbin:$PATH" | |
| # 2. Verify smartctl is accessible | |
| if ! command -v smartctl &> /dev/null; then | |
| echo "Error: smartctl not found. Please ensure it is installed in /usr/local/sbin." | |
| exit 1 | |
| fi | |
| # 3. Check for sudo/root privileges | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "This script must be run with sudo to access disk hardware." | |
| exit 1 | |
| fi | |
| echo "Searching for physical disks..." | |
| # 4. Get a list of all physical disk identifiers (e.g., /dev/disk0, /dev/disk1) | |
| # We filter diskutil to find 'physical' disks and ignore partitions/synthesized disks | |
| DISKS=$(diskutil list | grep "(\(internal\|external\), physical)" | awk '{print $1}') | |
| if [ -z "$DISKS" ]; then | |
| echo "No physical disks detected." | |
| exit 0 | |
| fi | |
| # 5. Loop through each disk and output SMART info | |
| for DISK in $DISKS; do | |
| echo "=========================================================================" | |
| echo " SMART REPORT FOR: $DISK" | |
| echo "=========================================================================" | |
| # -a displays all SMART information | |
| # Using 'smartctl' directly now that PATH is updated | |
| smartctl -a "$DISK" | |
| echo -e "\n" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment