Subversion Repositories programming

Rev

Rev 284 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
193 ira 1
#!/bin/bash
2
 
3
################################################################################
4
#
5
# Copyright (c) 2005,2006: Ira W. Snyder (devel@irasnyder.com)
6
# License: GNU General Public License v2 (or at your option, any later version)
7
#
8
################################################################################
9
 
283 ira 10
# This script needs dd, mktemp, smartctl, cstream, mailx, tee, sleep, echo,
11
# date, hostname, and rm in your path in order to work at all.
12
 
193 ira 13
################################################################################
14
###                            Config Options                                ###
15
################################################################################
16
 
284 ira 17
TMPFILE="$(mktemp)" || (echo "Failed to create tempfile" && exit 1)
193 ira 18
EMAIL_ADDR="ira@irasnyder.com"
241 ira 19
EMAIL_FILE="${TMPFILE}"
193 ira 20
RAID_DEVICE="/dev/md0"
21
RAID_DRIVES="/dev/sd[abcdefgh]"
283 ira 22
DD_SPD_LIMIT="80M"
23
SMART_SLEEP_TIME="160m"
193 ira 24
 
25
################################################################################
26
###                            Functions                                     ###
27
################################################################################
28
 
29
# Anything that needs to be run before the main program starts
30
# goes in this function
285 ira 31
function pre_startup () {
193 ira 32
}
33
 
34
# Anything that needs to be run after the main program finishes
35
# goes in this function
285 ira 36
function clean_up () {
193 ira 37
    if [ -f "$EMAIL_FILE"]; then
38
        echo "Removing: $EMAIL_FILE";
39
        rm "$EMAIL_FILE";
40
    fi
41
}
42
 
43
# Generate a nice header for the email
285 ira 44
function generate_header () {
193 ira 45
    echo "raid_checker v1.0"
46
    echo "Copyright (c) 2005,2006: Ira W. Snyder (devel@irasnyder.com)"
47
    echo "====================================================================="
48
    echo
49
}
50
 
51
################################################################################
52
###                            The main program                              ###
53
################################################################################
54
 
55
# Run pre-startup stuff
56
pre_startup
57
 
58
# Make the header
59
generate_header | tee -a "$EMAIL_FILE"
60
 
61
# Get start date / time
62
START_TIME="$(date)"
63
 
64
### Optional stuff, disabled for now, since you MUST be offline to perform
65
### both checks, and I don't want to have to go offline once a month.
66
 
67
# Check via read test
68
# echo "Running read-only check: e2fsck -c $RAID_DEVICE" | tee -a "$EMAIL_FILE"
69
# e2fsck -c "$RAID_DEVICE" 2>&1 | tee -a "$EMAIL_FILE"
70
 
71
# Check via non-destructive read-write test
72
# echo "Running non-destructive read-write check: e2fsck -c -c $RAID_DEVICE" | tee -a "$EMAIL_FILE"
73
# e2fsck -c -c "$RAID_DEVICE" 2>&1 | tee -a "$EMAIL_FILE"
74
 
75
# Read the whole disk. As of linux-2.6.15, md will regenerate bad data on
76
# a read error, then schedule a write of the good data back to disk. It
77
# should then re-read the newly written data to make sure it's ok.
78
#
79
# Source: http://www.ussg.iu.edu/hypermail/linux/kernel/0601.2/1200.html
80
#
81
echo "Reading the whole disk: dd if=${RAID_DEVICE} of=/dev/null" | tee -a "$EMAIL_FILE"
283 ira 82
dd if="${RAID_DEVICE}" | cstream -t"${DD_SPD_LIMIT}" -T300 -v1 -o- | tee -a "$EMAIL_FILE"
193 ira 83
echo | tee -a "$EMAIL_FILE"
84
echo | tee -a "$EMAIL_FILE"
85
 
86
# Run smartctl on each drive, sleeping in between each one
87
for d in $RAID_DRIVES;
88
    do echo "SMART checking drive: ${d}" | tee -a "$EMAIL_FILE"
89
    echo "=================================================" | tee -a "$EMAIL_FILE"
90
    smartctl -t long "${d}" 2>&1 | tee -a "$EMAIL_FILE"
91
    echo | tee -a "$EMAIL_FILE"
92
    echo | tee -a "$EMAIL_FILE"
283 ira 93
    sleep "${SMART_SLEEP_TIME}"
193 ira 94
    smartctl -d ata -l selftest "${d}" 2>&1 | tee -a "$EMAIL_FILE"
95
    echo | tee -a "$EMAIL_FILE"
96
    echo | tee -a "$EMAIL_FILE"
97
done;
98
 
99
# Get finish date / time
100
FINISH_TIME="$(date)"
101
 
102
# Print the final bits to the email
103
echo "Start time:  ${START_TIME}"  | tee -a "$EMAIL_FILE"
104
echo "Finish time: ${FINISH_TIME}" | tee -a "$EMAIL_FILE"
105
 
106
# Mail out the file
107
mailx -s "RAID Check Results from: $(hostname --fqdn)" "$EMAIL_ADDR" < "$EMAIL_FILE"
108
 
109
# Clean up the email file, etc.
110
clean_up
111