-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchk_badblocks.sh
executable file
·66 lines (57 loc) · 1.65 KB
/
chk_badblocks.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#
# chk_badblocks.sh - check hard drives for bad blocks to be called with a
# single argument, the device as shown in /dev.
# for example; ./chk_badblocks.sh /dev/sda
#
# should be root
if [ $UID -ne 0 ]; then
echo "$0 must be run as root"
exit 1
fi
# print usage if no args are passed
if [ $# -ne 1 ]; then
echo "usage: $0 <device>"
exit 1
fi
# set some variables
is_destructive=0 # (0=no, 1=yes)
ldevice=${1%/} # long device name
sdevice=`echo ${1%/} | sed 's/\/dev\///'`
logfile=chk_badblocks_${sdevice}.log
passes=20
mail="chad@planetmayfield.com"
# let's begin
echo "Beginning run of chk_badblocks." >> $logfile
echo "Run information" >> $logfile
echo " Device: $ldevice" >> $logfile
echo " Passes: $passes" >> $logfile
if [ $is_destructive -eq 0 ]; then
echo " Destructive: NO" >> $logfile
else
echo " Destructive: YES" >> $logfile
fi
# actually run badblocks
count=0
while [ $count -lt $passes ]; do
echo "---" >> $logfile
echo "Pass: $count" >> $logfile
echo "Start time: $(date)" >> $logfile
stime=$(date +%s)
# run either a destructive or non-destructive badblocks run
if [ $is_destructive -eq 0 ]; then
# non-destructive
badblocks -nsv -o bb_${sdevice}.txt $1 >> $logfile
else
# destructive
badblocks -wsv -o bb_${sdevice}.txt $1 >> $logfile
fi
etime=$(date +%s)
echo "End time: $(date)" >> $logfile
elapsed=`expr $etime - $stime`
echo "Elapsed time: `expr $elapsed \/ 60` minutes" >> $logfile
echo "---" >> $logfile
let count=count+1
done
# mail results
mailx -s "chk_badblocks.sh finished on $passes on $1" $mail < ./chk_badblocks_${sdevice}.log