Skip to content

Instantly share code, notes, and snippets.

@2600box
Last active January 7, 2024 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2600box/11edc10952e2c53cf50fd7bb46374ad9 to your computer and use it in GitHub Desktop.
Save 2600box/11edc10952e2c53cf50fd7bb46374ad9 to your computer and use it in GitHub Desktop.
hdsentinel script for use with proxmox

Step 1: download the free Linux 64-bit console version of HDSentinel; extract the single binary file, save it as /root/HDSentinel and make it executable Step 2: Add the following script: /root/hdsentinel.sh

#!/bin/bash
# cron script to warn on HDD health status changes

MinHealth=60
MaxTemp=55
StatusCmd="/root/HDSentinel -solid"
StatusCmdFull="/root/HDSentinel"
StatusFile=/root/HDSentinel.status
Warnings=""

declare -A LastHealthArray=()
if [ -f ${StatusFile} ]; then
  while read device temperature health pon_hours model sn size; do
    LastHealthArray[${device}]=${health}
  done < ${StatusFile}
fi

${StatusCmd} > ${StatusFile}
sync

declare -A HealthArray=()
while read device temperature health pon_hours model sn size; do
  HealthArray[${device}]=${health}
  if [[ -v "LastHealthArray[${device}]" ]]; then
    [ "${LastHealthArray[${device}]}" -eq "${health}" ] ||
      Warnings+="Device ${device} changed health status from ${LastHealthArray[${device}]} to ${health}\n"
  else
    Warnings+="Found new device: ${device}\n"
  fi
  (( ${health} < ${MinHealth} )) &&
    Warnings+="Device ${device} health = ${health} < ${MinHealth}\n"
  (( ${temperature} > ${MaxTemp} )) &&
    Warnings+="Device ${device} temperature = ${temperature} > ${MaxTemp}\n"
done < ${StatusFile}

for device in "${!LastHealthArray[@]}"
do
  [[ -v "HealthArray[${device}]" ]] ||
    Warnings+="Device ${device} missing\n"
done

if ! [ -z "${Warnings}" ]; then
  echo "----- WARNINGS FOUND -----"
  echo -e "${Warnings}"
  $StatusCmdFull
fi

Step 3: run the above script periodically, eg. hourly. Note This assumes you have configured your Linux/Proxmox system to forward emails meant for the system root to your own email address. Doing so is dependent on your own homelab setup and beyond the scope of this post. ln -s /root/hdsentinel.sh /etc/cron.hourly/hdsentinel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment