The disktemp script can output and notify disk devices temperatures (reading SMART data) on a GNU/Linux system.
The script output disk devices temperatures (echoing smartctl — so you do not need other tools or deamons such as hddtemp) and send a notification (using notify-send) when the temperature is over its limit. Outputs and notifies could be used by desktop panels, applets and notifiers to monitor disks temperatures.
See inside the script code for more details.
The disktemp script is free software, released under the terms of the GNU General Public License version 3 or (at your option) any later version.
Comments, suggestions and bug reports are welcome.
#!/bin/bash # # NAME # disktemp # # SYNOPSIS # Output and notify disk devices temperatures reading SMART data # # DESCRIPTION # This script is intended to output and notify disk devices temperatures # reading SMART data. Outputs and could be used by desktop panels, applets # and notifiers to monitor disks temperatures. # The script output disk devices temperatures (echoing smartctl) and send # a notification (using notify-send) when the temperature is over its limit. # Disk device list with respective labels and temperature limits should be # configured inside the script itself. # Temperature are read in Celsius degrees (the 'RAW_VALUE' of the SMART # vendor attribute 'Temperature_Celsius'). # If smartctl cannot read disk temperature (also if due to errors in the # configuration data inside the script) then the script output a 0 value and # sends an error notification. # The script must run with superuser rights. # # VERSION # 2.0 (2018-01-25) # # AUTHOR # Alexus # # COPYRIGHT # Copyright (c) 2016+ Alexus # License: GPLv3+ (GNU GPL version 3 or later) # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ## @file ## @name disktemp ## @brief Output and notify disk devices temperatures reading SMART data ## @author alexus ## @copyright GPLv3+ ## @version 2.0 ## @date 2018-01-25 ## @pre smartctl ## @pre notify-send ## @note Must run with superuser rights # Declarations declare -a disk_dev declare -a disk_lbl declare -a disk_tmax declare -i temp # °C declare -i alarm_ms # milliseconds declare -i errcode declare smartdata smartstat temp declare out out_pre out_post declare item # ### Script configuration ### disk_dev[0]='/dev/sda' disk_lbl[0]='a:' disk_tmax[0]=55 disk_dev[1]='/dev/sdb' disk_lbl[1]='b:' disk_tmax[1]=55 alarm_ms=3000 out_pre='| ' out_post='' #disk_dev[2]='--device=3ware,0 /dev/twe0' #disk_lbl[2]='c0:' #disk_tmax[2]=55 #disk_dev[3]='--device=3ware,1 /dev/twe0' #disk_lbl[3]='c1:' #disk_tmax[3]=55 alarm_ms=3000 out_pre='| ' out_post='' # ### End script configuration ### # Outputs and notifications for item in "${!disk_dev[@]}" ; do # read SMART data smartdata="$(sudo smartctl -A ${disk_dev[item]} 2>/dev/null)" smartstat=$? # read and output disk temp (awk used to strip the line feed) temp="$(echo "$smartdata" | grep -m 1 -i Temperature_Celsius | awk "{print \$10}")" out+="${disk_lbl[item]}$temp " # ckeck, notify, output if [[ $smartstat -ne 0 ]] || [[ $temp -le 0 ]] ; then notify-send -u "critical" -t "$alarm_ms" "ERROR READING DISK!" "${0##*/}: cannot read temperature from device '${disk_dev[item]}'.\nPlease:\n- check if device supports SMART, or\n- check disk's health, or\n- check internal script configuration." errcode=1 elif [[ "$temp" -gt "${disk_tmax[item]}" ]] ; then notify-send -u "critical" -t "$alarm_ms" "DISK TEMPERATURE ALARM!" "Device ${disk_dev[item]}: $temp C (limit is: ${disk_tmax[item]} C)." fi done echo -n "$out_pre$out$out_post" # Exit if [[ -z $errcode ]] ; then exit 0 ; else exit 1 ; fi