Skip to content

Commit

Permalink
hddtemp support removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
reefland committed Jul 17, 2023
1 parent 95e036e commit ced1f8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 90 deletions.
51 changes: 10 additions & 41 deletions 36-diskstatus
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# Originally Based on: https://github.com/yboetz/motd
#
# AUTHOR : Richard J. DURSO
# DATE : 07/17/2023
# VERSION : 1.10
# DATE : 07/18/2023
# VERSION : 1.11
##############################################################################

set -eu
Expand All @@ -25,7 +25,7 @@ if [ "$EUID" -ne 0 ]; then
fi

# Check if dependant utilities are installed
CHECK_UTILS="nvme smartctl nc"
CHECK_UTILS="nvme smartctl"
for checkname in $CHECK_UTILS
do
if ! command -v "${checkname}" >/dev/null 2>&1; then
Expand Down Expand Up @@ -57,11 +57,6 @@ red="\e[1;31m"
dim="\e[2m"
undim="\e[0m"

# hddtemp daemon connection info. Port numbers will be incremented to look for
# additional instances of hddtemp.
hddtemp_host=localhost
hddtemp_port=7634

# hddtemp can already report F or C temperatures for SATA devices. If this script
# grabs a temp from smartctl and it is reported in "C" set the following to
# if you want that value converted to F.
Expand Down Expand Up @@ -147,22 +142,6 @@ else
fi
set -e

# use nc to query temps from each hddtemp daemon instance, echo needed to get NC to return data
fetch_hddtemp=$(echo -n | nc ${hddtemp_host} ${hddtemp_port} |sed 's/|//m' | sed 's/||/ \n/g')

# See if we got any hddtemp data to work with
if [[ -n $fetch_hddtemp ]]; then
while [[ -n $fetch_hddtemp ]]
do
hddtemp+=$fetch_hddtemp
hddtemp_port=$((hddtemp_port+1))
fetch_hddtemp=$(echo -n | nc $hddtemp_host $hddtemp_port |sed 's/|//m' | sed 's/||/ \n/g')
done
else
# This value is not tested for, might be handy in debugging
hddtemp="none"
fi

out=""

# generate data to display about devices
Expand Down Expand Up @@ -228,7 +207,7 @@ for i in "${!disksalias[@]}"; do #for every /dev/sdX device name
# examples:
# status_field : 0x4004(INVALID_FIELD: A reserved coded value or an unsupported value in a defined field)
# status_field : 0xc502(READ_ERROR: The read data could not be recovered from the media)
error_status_code=$(nvme error-log -e 1 "/dev/${disksalias[$i]}" | awk -F '[(:]' '/^status_field/{print $3}')
error_status_code=" $(nvme error-log -e 1 "/dev/${disksalias[$i]}" | awk -F '[(:]' '/^status_field/{print $3}')"

fi
else
Expand All @@ -244,23 +223,13 @@ for i in "${!disksalias[@]}"; do #for every /dev/sdX device name
devicetmp=$(smartctl -A "/dev/${disksalias[$i]}" | awk '/^Temperature:/{print $2, $3}')
temp=$(echo "${devicetmp}" | awk '{print $1}')
unit=$(echo "${devicetmp}" | awk '{print substr($2,1,1)}') # Only need 1st character

# Not nvme see if we have hddtemp data
else
# Get Temperature and Unit
temp=$( (grep "${disksalias[$i]}" <<< "${hddtemp}") | cut -d "|" -f3)
# Get The Unit from the temperature
unit=$( (grep "${disksalias[$i]}" <<< "${hddtemp}") | cut -d "|" -f4)
unit=${unit% } # Trim trailing space if it has it

# If no temp data collected from hddtemp, fallback to smartctl
if [ -z "$temp" ]; then
# Assume something like:
# "194 Temperature_Celsius 0x0022 025 055 000 Old_age Always - 25 (Min/Max 22/44)"
# "190 Airflow_Temperature_Cel 0x0032 070 056 000 Old_age Always - 30"
temp=$(smartctl -A "/dev/${disksalias[$i]}" | awk '/.*Temperature_Cel.*/{print $10}')
unit="C"
fi
# Get SATA device temp from smartctl
# Assume something like:
# "194 Temperature_Celsius 0x0022 025 055 000 Old_age Always - 25 (Min/Max 22/44)"
# "190 Airflow_Temperature_Cel 0x0032 070 056 000 Old_age Always - 30"
temp=$(smartctl -A "/dev/${disksalias[$i]}" | awk '/.*Temperature_Cel.*/{print $10}')
unit="C"
fi

# if we have a temp see if we need to convert to F
Expand Down
53 changes: 4 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Collection of 'Message of the Day' scripts with ZFS Enhancements

* [update-motd](https://launchpad.net/update-motd)
* [figlet](http://www.figlet.org/) & [lolcat](https://github.com/busyloop/lolcat) (for `10-hostname`)
* [smartmontools](https://www.smartmontools.org/), [nvme-cli](https://packages.ubuntu.com/search?keywords=nvme-cli), [hddtemp](https://savannah.nongnu.org/projects/hddtemp/) [optional] (for `36-diskstatus`)
* [smartmontools](https://www.smartmontools.org/) & [nvme-cli](https://packages.ubuntu.com/search?keywords=nvme-cli) (for `36-diskstatus`)

### How do I set it up?

Expand All @@ -16,7 +16,7 @@ option set to `yes` in your sshd config.
The duplicate files are different versions of the same, use either one of them. E.g. `30-zpool-simple`
will not print usage bars.

The script `36-diskstatus` will grep either *journalctl* or *syslog* for `smartd` entries to read last self-test result. You have to enable smartd monitoring & run regular self-tests for it to display anything. The nvme client is required to get NVMe device errors and wear leveling.
The script `36-diskstatus` will grep either *journalctl* or *syslog* for `smartd` entries to read last self-test result. For non-NVMe devices, you have to enable smartd monitoring & run regular self-tests for it to display anything. The nvme client is required to get NVMe device errors and wear leveling.

If you use `50-fail2ban` you should comment out the `compress` option in `/etc/logrotate.d/fail2ban`,
so that the logs are not compressed and can be read by grep.
Expand All @@ -25,54 +25,9 @@ so that the logs are not compressed and can be read by grep.

---

## HDDTemp not Required
## HDDTemp Removed

The `hddtemp` utility was once the primary way to monitor and gather drive temperature information. However HDDTemp project is considered dead and no longer maintained. It is no longer included in many distribution repositories. If you do not have HDDTemp this script will fallback to scraping `smartctl` for temperature information.

---

### Adding Sensors to HDDTemp

Since HDDTemp project is no longer maintained it lacks database entries for many not so new technologies. It should be straight forward to add sensors for SATA SSD devices, but it lacks any NVMe support.

If `hddtemp` is unable to locate a temperature sensor but `smartctl` shows a sensor attribute exists, it can be added:

```shell
$ sudo hddtemp /dev/sda
WARNING: Drive /dev/sda doesnt seem to have a temperature sensor.
WARNING: This doesnt mean it hasnt got one.
WARNING: If you are sure it has one, please contact me ([email protected]).
WARNING: See --help, --debug and --drivebase options.
/dev/sda: Samsung SSD 840 Series : no sensor

$ sudo smartctl -a /dev/sda | grep -i temp
190 Airflow_Temperature_Cel 0x0032 077 060 000 Old_age Always - 23

```

NOTE: Attribute `194` is common for Hard Drives, however many SSDs use attribute `190` for a temperature sensor, this can be added to the HDDTemp database:

```bash
$ sudo sh -c 'echo \"Samsung SSD \(840\|860\)\" 190 C \"Temp for Samsung SSDs\" >> /etc/hddtemp.db'

# Check entry
$ tail -1 /etc/hddtemp.db
"Samsung SSD (840|860)" 190 C "Temp for Samsung SSDs"
```

_Note: All the `\` characters are required, it tells bash not to interpret the following character, accept it as a literal._

* Field 1: Use a string or regular expression matching the drive's display name (as reported by hddtemp output)
* Field 2: SMART data field number (190 in this case)
* Field 3: temperature unit (C|F)
* Field 4: label string / comment you define

Once added to the HDDTemp Database, HDDTemp should show device temperature:

```shell
$ sudo hddtemp /dev/sda
/dev/sda: Samsung SSD 840 Series: 22 C
```
The `hddtemp` utility was once the primary way to monitor and gather drive temperature information. However HDDTemp project is considered dead and no longer maintained. It is no longer included in many distribution repositories. Support for `hddtemp` has been removed. This script will get device temperature from `smartctl`.

---

Expand Down

0 comments on commit ced1f8d

Please sign in to comment.