Rev 285 | 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 mktemp, smartctl, mailx, tee, sleep, echo,# date, hostname, and rm in your path in order to work.################################################################################### Config Options ###################################################################################TMPFILE="$(mktemp)" || (echo "Failed to create tempfile" && exit 1)EMAIL_ADDR=""EMAIL_FILE="${TMPFILE}"RAID_DEVICE="/dev/md0"RAID_DRIVE_BASE="/dev/sd"RAID_DRIVE_LETTERS="a b c d e f g h"SMART_SLEEP_TIME="160m"# Call clean_up() on interrupttrap clean_up SIGHUP SIGINT SIGTERM################################################################################### 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 () {for l in $RAID_DRIVE_LETTERS; doremove_file "${EMAIL_FILE}.${l}"doneremove_file "${EMAIL_FILE}"}function remove_file () {if [ -f "$1" ]; thenecho "Removing: $1"rm "$1"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.# Run smartctl on each drive, giving the output to a different file# for each drivefor l in $RAID_DRIVE_LETTERS; doDRIVE="${RAID_DRIVE_BASE}${l}"DRIVE_FILE="${EMAIL_FILE}.${l}"echo "SMART checking drive: ${DRIVE}" | tee -a "$DRIVE_FILE"echo "=================================================" | tee -a "$DRIVE_FILE"smartctl -t long "${DRIVE}" 2>&1 | tee -a "$DRIVE_FILE"echo | tee -a "$DRIVE_FILE"echo | tee -a "$DRIVE_FILE"done# Sleep to give time for all drives to do their thingsleep "${SMART_SLEEP_TIME}"# Get the results of thest for each drive, giving the output to a different# file for each drivefor l in $RAID_DRIVE_LETTERS; doDRIVE="${RAID_DRIVE_BASE}${l}"DRIVE_FILE="${EMAIL_FILE}.${l}"smartctl -d ata -l selftest "${DRIVE}" 2>&1 | tee -a "$DRIVE_FILE"echo | tee -a "$DRIVE_FILE"echo | tee -a "$DRIVE_FILE"done# Accumulate the results into the main filefor l in $RAID_DRIVE_LETTERS; doDRIVE_FILE="${EMAIL_FILE}.${l}"cat "$DRIVE_FILE" >> "$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 files, etc.clean_up