Skip to content

Instantly share code, notes, and snippets.

@wkettler
Last active February 27, 2024 23:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wkettler/a93644ec101d3b6cfb6c to your computer and use it in GitHub Desktop.
Save wkettler/a93644ec101d3b6cfb6c to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# hddcheck.sh
#
# Modified version of http://www.cyberciti.biz/files/scripts/monitor-my-hard-disk.sh.txt.
#
# Generate a warning email based on hard drive temps.
#
TO=test@test.com
HDDS="/dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi"
HDT=/usr/sbin/hddtemp
LOG=/usr/bin/logger
DOWN=/sbin/shutdown
MAIL=/usr/bin/mail
HOSTNAME=$(hostname)
ALERT_LEVEL=50
for disk in $HDDS; do
if [[ -b $disk ]]; then
HDTEMP=$($HDT $disk | awk '{print $NF}' | awk -F '°' '{print $1}')
if [[ $HDTEMP -ge $ALERT_LEVEL ]]; then
# MSG="System going down $disk temperature $HDTEMP°C crossed its limit"
MSG="$disk temperature $HDTEMP°C crossed its limit"
# Log to syslog
$LOG "${MSG}"
# Send email
echo "${MSG}" | ${MAIL} -s "ERROR: $HOSTNAME disk temperature" ${TO}
# Shutdown the system
# $DOWN -h 0
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment