Last active
December 29, 2023 11:52
-
-
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).
This file contains 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 | |
# 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 |
I'm glad it's helpful to you
…On Mon, May 31, 2021, 12:18 PM teezyyoxo ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
this is awesome, thank you!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/7592005#gistcomment-3764026>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYD7POUS7AFHZ4VHRC7RYLTQPHFVANCNFSM453JIEIQ>
.
Switching to this will better support SAS disks:
sudo smartctl -H $drive 2>/dev/null |
grep '^SMART overall\|^SMART Health Status' |
rev | cut -d ' ' -f1 | rev
work gr8
Thanks, I'm so glad to hear this is useful to you.
How can this code be modified to exclude drives marked as "unavailable?
This isn't a situation with which I'm personally familiar, and since I'm
unable to replicate it on my own system, I don't think I can provide you
with a solution at this time.
…On Thu, Dec 1, 2022, 6:21 PM dgyioulos ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
How can this code be modified to exclude drives marked as "unavailable?
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/7592005#gistcomment-4388143> or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYD7PIZZW3HW7TAGAMKOW3WLFFHTBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFU43TKOJSGAYDLJ3UOJUWOZ3FOKTGG4TFMF2GK>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Modify line 14 to include nvme:
for drive in /dev/sd[a-z] /dev/sd[a-z][a-z] /dev/nvme[0-9]n[0-9]
That's a great enhancement, thank you, ***@***.**** !
…On Thu, Jan 26, 2023 at 10:02 AM drakos ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Modify line 14 to include nvme:
for drive in /dev/sd[a-z] /dev/sd[a-z][a-z] /dev/nvme[0-9]n[0-9]
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/7592005#gistcomment-4449809> or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYD7PIB5XDDIFTQVI2H42TWUKUZJBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFU43TKOJSGAYDLJ3UOJUWOZ3FOKTGG4TFMF2GK>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
If anyone is interested, I ended up taking this a bit further. It lists all disks, supports outputting to JSON (I have a crontab job that sends the results to node-red and does alerting), but also supports showing the remaining life of a lot of SSDs (mostly enterprise):
https://github.com/BloodBlight/CephNotes/blob/main/SmartHealth
There is also a ListDisks script that shows a lot of details in one quick script:
https://github.com/BloodBlight/CephNotes/blob/main/ListDisks
thank BloodBlight
Why not just use lsblk
for disk in $(lsblk --json | jq -r '.blockdevices[].name'); do smartctl --all /dev/${disk}; don
That option didn't exist at the time I wrote this code. Maybe it's time
for an update? Send a pull request, my friend 😊
…On Sat, Nov 4, 2023, 10:27 AM Rush ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Why not just use lsblk
for disk in $(lsblk --json | jq -r '.blockdevices[].name'); do smartctl --all /dev/${disk}; don
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/tommybutler/7592005#gistcomment-4749529> or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAYD7POZWYPYPMQ4OMYPOGTYCZUHHBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFU43TKOJSGAYDLJ3UOJUWOZ3FOKTGG4TFMF2GK>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is awesome, thank you!