forked from yboetz/motd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path37-nvmestatus
63 lines (55 loc) · 1.61 KB
/
37-nvmestatus
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
#!/bin/bash
# config
MAX_TEMP=40
# set column width
COLUMNS=2
# colors
white="\e[39m"
green="\e[1;32m"
red="\e[1;31m"
dim="\e[2m"
undim="\e[0m"
# NVMe devices to check
nvm_disks=(nvme0n1 nvme1n1)
nvm_names=(nvme0n1 nvme1n1)
# logfiles to check
logfiles='/var/log/syslog /var/log/syslog.1'
# get all lines with smartd entries from syslog
lines=$(tac $logfiles | grep -hiP 'smartd\[[[:digit:]]+\]:' | grep -iP "previous self-test")
out=""
for i in "${!nvm_disks[@]}"; do
nvm_disk=${nvm_disks[$i]}
# use nvm_names if given
nvm_name=${nvm_names[$i]}
if [ -z "${nvm_name}" ]; then
nvm_name=$nvm_disk
fi
uuid=$(blkid -s UUID -o value "/dev/${nvm_disk}")
status=$( (grep "${uuid}" <<< "${lines}") | grep -m 1 -oP "previous self-test.*" | awk '{ print $4 " " $5 }')
temp=$(sudo nvme smart-log "/dev/${nvm_disk}" | grep -m 1 "temperature" | awk '{print $3}')
# color green if temp <= MAX_TEMP, else red
if [[ "${temp}" -gt "${MAX_TEMP}" ]]; then
color=$red
else
color=$green
fi
# add "C" to temperature
if [[ "$temp" =~ ^[0-9]+$ ]]; then
temp="${temp}C"
fi
# color green if status is "without error", else red
if [[ "${status}" == "without error" ]]; then
status_color=$green
else
status_color=$red
fi
# print temp & smartd error
out+="${nvm_name}:,${color}${temp}${undim} | ${status_color}${status}${undim},"
# insert \n every $COLUMNS column
if [ $((($i+1) % $COLUMNS)) -eq 0 ]; then
out+="\n"
fi
done
out+="\n"
printf "\nNVMe disk status:\n"
printf "$out" | column -ts $',' | sed -e 's/^/ /'