Subversion Repositories programming

Rev

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