Subversion Repositories programming

Rev

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