Rev 284 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/bin/bash################################################################################## Copyright (c) 2005,2006: Ira W. Snyder (devel@irasnyder.com)# License: GNU General Public License v2 (or at your option, any later version)################################################################################## This script needs dd, mktemp, smartctl, cstream, mailx, tee, sleep, echo,# date, hostname, and rm in your path in order to work at all.################################################################################### Config Options ###################################################################################TMPFILE="$(mktemp)" || (echo "Failed to create tempfile" && exit 1)EMAIL_ADDR="ira@irasnyder.com"EMAIL_FILE="${TMPFILE}"RAID_DEVICE="/dev/md0"RAID_DRIVES="/dev/sd[abcdefgh]"DD_SPD_LIMIT="80M"SMART_SLEEP_TIME="160m"################################################################################### Functions #################################################################################### Anything that needs to be run before the main program starts# goes in this functionfunction pre_startup () {}# Anything that needs to be run after the main program finishes# goes in this functionfunction clean_up () {if [ -f "$EMAIL_FILE"]; thenecho "Removing: $EMAIL_FILE";rm "$EMAIL_FILE";fi}# Generate a nice header for the emailfunction generate_header () {echo "raid_checker v1.0"echo "Copyright (c) 2005,2006: Ira W. Snyder (devel@irasnyder.com)"echo "====================================================================="echo}################################################################################### The main program #################################################################################### Run pre-startup stuffpre_startup# Make the headergenerate_header | tee -a "$EMAIL_FILE"# Get start date / timeSTART_TIME="$(date)"### Optional stuff, disabled for now, since you MUST be offline to perform### both checks, and I don't want to have to go offline once a month.# Check via read test# echo "Running read-only check: e2fsck -c $RAID_DEVICE" | tee -a "$EMAIL_FILE"# e2fsck -c "$RAID_DEVICE" 2>&1 | tee -a "$EMAIL_FILE"# Check via non-destructive read-write test# echo "Running non-destructive read-write check: e2fsck -c -c $RAID_DEVICE" | tee -a "$EMAIL_FILE"# e2fsck -c -c "$RAID_DEVICE" 2>&1 | tee -a "$EMAIL_FILE"# Read the whole disk. As of linux-2.6.15, md will regenerate bad data on# a read error, then schedule a write of the good data back to disk. It# should then re-read the newly written data to make sure it's ok.## Source: http://www.ussg.iu.edu/hypermail/linux/kernel/0601.2/1200.html#echo "Reading the whole disk: dd if=${RAID_DEVICE} of=/dev/null" | tee -a "$EMAIL_FILE"dd if="${RAID_DEVICE}" | cstream -t"${DD_SPD_LIMIT}" -T300 -v1 -o- | tee -a "$EMAIL_FILE"echo | tee -a "$EMAIL_FILE"echo | tee -a "$EMAIL_FILE"# Run smartctl on each drive, sleeping in between each onefor d in $RAID_DRIVES;do echo "SMART checking drive: ${d}" | tee -a "$EMAIL_FILE"echo "=================================================" | tee -a "$EMAIL_FILE"smartctl -t long "${d}" 2>&1 | tee -a "$EMAIL_FILE"echo | tee -a "$EMAIL_FILE"echo | tee -a "$EMAIL_FILE"sleep "${SMART_SLEEP_TIME}"smartctl -d ata -l selftest "${d}" 2>&1 | tee -a "$EMAIL_FILE"echo | tee -a "$EMAIL_FILE"echo | tee -a "$EMAIL_FILE"done;# Get finish date / timeFINISH_TIME="$(date)"# Print the final bits to the emailecho "Start time: ${START_TIME}" | tee -a "$EMAIL_FILE"echo "Finish time: ${FINISH_TIME}" | tee -a "$EMAIL_FILE"# Mail out the filemailx -s "RAID Check Results from: $(hostname --fqdn)" "$EMAIL_ADDR" < "$EMAIL_FILE"# Clean up the email file, etc.clean_up