Skip to content

Commit 54b2286

Browse files
committed
Add a tool for setting TLER automatically.
1 parent 700fccd commit 54b2286

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tlerActiveation.tool

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# shellcheck disable=SC1004,SC2236
3+
4+
5+
6+
7+
function tler_activation() {
8+
local tlerStatus
9+
10+
tlerStatus="$(smartctl -jl scterc "/dev/${drive}" | jq -Mre '.ata_sct_erc | values')"
11+
12+
13+
if [ ! -z "${tlerStatus}" ]; then
14+
if [ ! "$(echo "${tlerStatus}" | jq -Mre '.read.enabled | values')" = "true" ] || [ ! "$(echo "${tlerStatus}" | jq -Mre '.write.enabled | values')" = "true" ]; then
15+
smartctl -l scterc,70,70 "/dev/${drive}"
16+
fi
17+
fi
18+
19+
echo "${drive}:"
20+
smartctl -l scterc "/dev/${drive}" | tail -n +4
21+
echo "+---------------+"
22+
}
23+
24+
function drive_list() {
25+
# Reorders the drives in ascending order
26+
# FixMe: smart support flag is not yet implemented in smartctl json output.
27+
readarray -t "drives" <<< "$(for drive in $(sysctl -n kern.disks | sed -e 's:nvd:nvme:g'); do
28+
if smartctl --json=u -i "/dev/${drive}" | grep "SMART support is:" | grep -q "Enabled"; then
29+
printf "%s " "${drive}"
30+
elif echo "${drive}" | grep -q "nvme"; then
31+
printf "%s " "${drive}"
32+
fi
33+
done | tr ' ' '\n' | sort -V | sed '/^nvme/!H;//p;$!d;g;s:\n::')"
34+
}
35+
36+
37+
38+
39+
# Check if needed software is installed.
40+
PATH="${PATH}:/usr/local/sbin:/usr/local/bin"
41+
commands=(
42+
sysctl
43+
sed
44+
grep
45+
tr
46+
smartctl
47+
jq
48+
sort
49+
tail
50+
)
51+
for command in "${commands[@]}"; do
52+
if ! type "${command}" &> /dev/null; then
53+
echo "${command} is missing, please install" >&2
54+
exit 100
55+
fi
56+
done
57+
58+
59+
60+
61+
drive_list
62+
63+
for drive in "${drives[@]}"; do
64+
tler_activation
65+
done

0 commit comments

Comments
 (0)