Skip to content

Instantly share code, notes, and snippets.

@tommybutler
Last active January 14, 2026 12:45
Show Gist options
  • Select an option

  • Save tommybutler/7592005 to your computer and use it in GitHub Desktop.

Select an option

Save tommybutler/7592005 to your computer and use it in GitHub Desktop.
Script to quickly scan the S.M.A.R.T. health status of all your hard drive devices in Linux (at least all the ones from /dev/sda to /dev/sdzz). You need smartctl installed on your system for this script to work, and your hard drives need to have S.M.A.R.T. capabilities (they probably do).
#!/bin/bash
# install the smartctl package first! (apt-get install smartctl)
if sudo true
then
true
else
echo 'Root privileges required'
exit 1
fi
for drive in /dev/sd[a-z] /dev/sd[a-z][a-z]
do
if [[ ! -e $drive ]]; then continue ; fi
echo -n "$drive "
smart=$(
sudo smartctl -H $drive 2>/dev/null |
grep '^SMART overall' |
awk '{ print $6 }'
)
[[ "$smart" == "" ]] && smart='unavailable'
echo "$smart"
done
@Fl1pp3d0ff
Copy link

Fl1pp3d0ff commented Jan 14, 2026

This will allow for both SAS and SATA drives:

for drive in /dev/sd[a-z] /dev/sd[a-z][a-z]
do
if [[ ! -e $drive ]]; then continue ; fi

echo -n "$drive "
smart=$(
smartctl -H $drive 2>/dev/null |
grep '^SMART' |
awk '{print $NF}'
)
[[ "$smart" == "" ]] && smart='unavailable'
echo "$smart"
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment