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


Click here to return to the 'Cron job script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
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 | # ]