-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-sd-x.sh
executable file
·87 lines (70 loc) · 1.77 KB
/
test-sd-x.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
## test sd card / USB stick
## global variables
SCRIPT=`basename $0`
DEBUG=false
VERBOSE=true
## script specific variables
DEFAULTDEVICE="/dev/sdb"
## end script specific variables
(${DEBUG}) && set -x
#warning, this will terminate the script on errors
#do not use this if errors are expected behavior!
set -e
## display usage on invalid amount of arguments or help arguments
usage()
{
echo "usage: $SCRIPT"
echo " $SCRIPT -h|--help"
echo "test SD card / USB stick for fake sizes or bad storage with f3probe and badblocks"
echo ""
echo "arguments"
echo " -h|--help display help information"
echo ""
exit 1
}
#if arguments > 1 or first argument == -h| --help show usage
if [ $# -gt 1 -o "$1" == "-h" -o "$1" == "--help" ]
then
usage
fi
read -p "device to test? [${DEFAULTDEVICE}]: " DEVICE
if [ "${DEVICE}" == "" ]
then
DEVICE=${DEFAULTDEVICE}
fi
read -p "test in RW mode? [Y/n]: " WRITE
if [ "${WRITE}" == "" -o "${WRITE}" == "y" -o "${WRITE}" == "Y" ]
then
WRITE=true
else
WRITE=false
fi
## VERBOSE
(${VERBOSE}) && echo "device: ${DEVICE}"
(${VERBOSE}) && echo "write mode: ${WRITE}"
MOUNTED=`mount | grep ${DEVICE} | awk '{ print $1 }'`
for MOUNT in ${MOUNTED}
do
echo "umounting ${MOUNT}"
umount ${MOUNT}
done
sleep 5
DATETIME=`date +"%Y-%m-%d %H:%M"`
echo "### started at ${DATETIME} ###"
if [ ${WRITE} == "true" ]
then
sleep 5
echo "### running f3probe in destructive mode ###"
f3probe --destructive --time-ops ${DEVICE}
echo "### running badblocks in write mode ###"
badblocks -w -v ${DEVICE}
else
echo "### running f3probe in RO mode ###"
f3probe --time-ops ${DEVICE}
echo "### running badblocks in RO mode ###"
badblocks -v ${DEVICE}
fi
DATETIME=`date +"%Y-%m-%d %H:%M"`
echo "### finished at ${DATETIME} ###"
exit 0