summaryrefslogtreecommitdiffstats
path: root/remote/modules/smartctl/data/opt/openslx/scripts/systemd-smartctl
blob: 6025c962e5c285f83f55ca0ce3906ee6ca5eecdf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/ash

# Check Reallocated_Sector_Ct and Spin_Retry_Count of local disk(s)

FILE=$(mktemp)
for dev in /dev/sd?; do
	smartctl -A "$dev" -f "brief" > "$FILE" || continue # should we report devices where smartctl doesn't work?
	REALLOC=$(grep "^ *5 " "$FILE" | awk '{print $8}')
	SPINRETRY_VAL=$(grep "^ *10 " "$FILE" | awk '{print $4}')
	SPINRETRY_THR=$(grep "^ *10 " "$FILE" | awk '{print $6}')
	if [ -n "$REALLOC" ] && [ "$REALLOC" != "0" ]; then
		slxlog "smartctl-realloc" "Failing HDD: $dev has $REALLOC reallocated sectors!" "$FILE"
	fi
	if [ -n "$SPINRETRY_VAL" ] && [ "$SPINRETRY_VAL" -le "$SPINRETRY_THR" ]; then
		slxlog "smartctl-spinretry" "Failing HDD: $dev has bad spin retry count! ($SPINRETRY_VAL/$SPINRETRY_THR)" "$FILE"
	fi
done
rm -f -- "$FILE"