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