Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Get hard disk SMART status from the command line UNIX
SMART is a technology that hard drives use to perform self-checks. This can generally tell when a drive is "about to fail." You can get the SMART status of your hard disk from the command line with the following command:
 % diskutil info disk0 | grep SMART
If you only have one hard disk, it is generally disk0; if you have others, run:
 % diskutil list
to find their numbers. Someone with more time on their hands than I can probably roll this into a shell script that's run via a cron job, checking, say, once a day, which can alert users when the disk is about to fail. Since no one thinks of checking regularly, this info could be a real lifesaver.

[robg adds: This data is also available in the Disk Utility program, via the Info button in the toolbar. The command line version, though, enables you to easily check disks remotely. Most likely, all you'll see is a message that says "SMART Status: Verified" ... if you ever do not see that, though, that's when it's time to think about making a fresh backup!]
    •    
  • Currently 2.14 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[77,066 views]  

10.3: Get hard disk SMART status from the command line | 11 comments | Create New Account
Click here to return to the '10.3: Get hard disk SMART status from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Your wish is my command...
Authored by: ExecutiveEditor on Nov 28, '03 12:53:30PM
Check SMART Status.

Click the link above to open the script in Script Editor, save, and enter the following line into your crontab:

osascript [path/to/file]

where path/to/file is, obviously, the POSIX path to the Applescript.

[ Reply to This | # ]
Your wish is my command...
Authored by: ExecutiveEditor on Nov 28, '03 12:55:49PM

One mistake--make sure you place the POSIX path to the script in quotation marks: osascript "/path/to/file". Sorry about that



[ Reply to This | # ]
OK, let's try this one more time...
Authored by: ExecutiveEditor on Nov 28, '03 01:07:52PM
Check SMART Status.scpt.

Click the link above to open the script in Script Editor, save, and enter the following line into your crontab:

osascript "/path/to/file"

where /path/to/file is, obviously, the POSIX path to the Applescript.

[Corrected the script to ask Finder to display the dialog if there is an error--osascript can't display dialogs directly. Rob, if you want, delete the previous two comments and move this up. Sorry about that.]

[ Reply to This | # ]
OK, let's try this one more time...
Authored by: mcroft on Nov 29, '03 02:50:29AM
This version should discover your drives.

set disklist to do shell script "diskutil list | grep /dev/"

set EachDisk to words in disklist

repeat with CurrentDisk in EachDisk
	if CurrentDisk as text is not equal to "dev" then
		try
			set status to do shell script "diskutil info " & CurrentDisk & " | grep SMART"
			if not (status is "   SMART Status:       Verified" or status is "   SMART Status:       Not Supported") then
				tell application "Finder"
					display dialog "A hardware problem has been detected on your hard drive:" & return & return & status
				end tell
			end if
		on error errStr
			tell application "Finder"
				display dialog errStr
			end tell
		end try
	end if
end repeat


[ Reply to This | # ]
Geektool to the rescue
Authored by: beerguy on Aug 06, '04 11:45:48AM

I just made a geektool entry of "diskutil info disk0 | grep Verified > /dev/null"

Then I set the default icons and turned on icon display. If disk status is "Verified" then I get a green icon, if it's not I get red.



[ Reply to This | # ]
Perhaps a little better script
Authored by: cyberbrent on Nov 29, '03 02:37:17AM

I edited the script as I wanted to have a DAILY HARD DRIVE VERIFIED STATUS message window displayed, not just when the "Drive Failed".

Click on the link below and it will automatically download to your computer (This link will expire Dec.31.2003):

http://homepage.mac.com/cyberbrent/filechute/SMART_Disk_Check.zip

I also used CRONNIX to add the scheduled time for this script to run daily under my user name CRONTAB. This is a very simply program for a newbie or advanced user - nice GUI.

http://www.macupdate.com/info.php/id/7486

Regards

Brent

---
"You alone define your limitations"



[ Reply to This | # ]
QUESTION: 10.3: Get hard disk SMART status from the command line
Authored by: DaddyWags on Nov 29, '03 11:33:39AM

Question: Is the SMART status verified a) when the diskutil utility is run, b) only at boot-up, or c) once every xx hrs?

Does anybody know the answer?

For some reason I have it in my head that the SMART status is checked maybe only at boot-up, status is stored somewhere, and then diskutil simply retrieves the status from that "somewhere".

Am I wrong?



[ Reply to This | # ]
Cron job script
Authored by: macubergeek on Dec 01, '03 02:03:45PM
heres a script you can launch on cron and it'll notify you when the result comes back bad: you need to replace youremail@whatever.com with the email address you want the alert sent to.

#!/bin/sh
############################
## declare some variables ##
############################
driveok="Verified"
drivecheck=`diskutil info disk0 | grep SMART | awk '{ print $3 }'`
################
## do my test ##
################
if [ $drivecheck != $driveok ]
then
diskutil info disk0 | grep SMART > /tmp/diskcheck
mail -s "Disk Check" youremail@whatever.com < /tmp/diskcheck && rm /tmp/diskcheck
fi


[ Reply to This | # ]
slight refinement...
Authored by: gatorparrots on Jan 14, '04 08:19:20PM
The grep process is unnecessary in returning the status, as awk has its own pattern matching. Also, to get better output, you should print both the third and fourth fields, to handle "Not Supported" or other multi-word output:
diskutil info disk0 | awk '/SMART/ {print $3,$4}'


[ Reply to This | # ]
Cron job script
Authored by: allanmarcus on Mar 17, '04 11:07:32AM
This script should test all your attached drives.

#!/bin/sh

# Script to test SMART status of mounted drives
# By Allan Marcus
# Los Alamos National Laboratory
# 2004-02-25
# This script and its contents are placed in the public domain by the author

# First get the list of devices
DISKS=($(diskutil list | grep ^\/))

# Set a warning flag to 0 - everything OK
# will be set to 1 if there is a problem later
WARNING=0

# If you want to do something if there is a reported problem
# then do it here.
# Note that mail (sendmail) is not set up to send mail by
# default on a Mac, so you can't just use "mail"
on_warning() {
	echo "***DANGER WILL ROBINSON***"
	echo "A SMART problem was reported with $1"
	echo
}

# now loop through each device and test to see if it's SMART enabled,
# and verified

for ((index=0 ; index < ${#DISKS[*]} ; index++ ))
do
	echo
	echo "Results for ${DISKS[index]}"
	df -h | grep ${DISKS[index]}
	RESULT=$(diskutil info ${DISKS[index]} | grep "SMART Status")
	if [ $? == 0 ]; then
		echo "     $RESULT"
		if ! echo $RESULT | grep -q Verified ; then
			# set the warning for the exit status
			on_warning ${DISKS[index]}
			WARNING=1
		fi
	else	
		echo "     SMART not supported on this device "
		echo "     (generally only supported on IDE hard drives)"
	fi
done
exit $WARNING[</code]


[ Reply to This | # ]
10.3: Get hard disk SMART status from the command line
Authored by: loren_ryter on Feb 08, '09 08:30:31AM

This command makes a horrible drive parking noise on an intel MBP running 10.5.6. Anyone else experience this or know another method, or the cause of this noise?



[ Reply to This | # ]