Rev 193 | 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)
#
################################################################################
################################################################################
### 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]"
################################################################################
### Functions ###
################################################################################
# Anything that needs to be run before the main program starts
# goes in this function
pre_startup() {
}
# Anything that needs to be run after the main program finishes
# goes in this function
clean_up() {
if [ -f "$EMAIL_FILE"]; then
echo "Removing: $EMAIL_FILE";
rm "$EMAIL_FILE";
fi
}
# Generate a nice header for the email
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 stuff
pre_startup
# Make the header
generate_header | tee -a "$EMAIL_FILE"
# Get start date / time
START_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}" of=/dev/null 2>&1 | tee -a "$EMAIL_FILE"
echo | tee -a "$EMAIL_FILE"
echo | tee -a "$EMAIL_FILE"
# Run smartctl on each drive, sleeping in between each one
for 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 160m
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 / time
FINISH_TIME="$(date)"
# Print the final bits to the email
echo "Start time: ${START_TIME}" | tee -a "$EMAIL_FILE"
echo "Finish time: ${FINISH_TIME}" | tee -a "$EMAIL_FILE"
# Mail out the file
mailx -s "RAID Check Results from: $(hostname --fqdn)" "$EMAIL_ADDR" < "$EMAIL_FILE"
# Clean up the email file, etc.
clean_up