Hard Drive Temperature Script?

Status
Not open for further replies.

ere109

Contributor
Joined
Aug 22, 2017
Messages
190
I've had continous SMART warnings about two drives getting too hot. After reading several pages, I compiled a terminal command that displays all of my hard drive temperatures. It's nice, but cumbersome. I have to paste it in, every time, and in order to save the data I'd have to manually record. I've never tried to write a script, but suspect there's a way to turn my command into a script that would run hourly and compile a database of historic hard drive temperatures - maybe even one that would cut out all the extraneous data and just record the current temperature without anything else. I searched and couldn't find anything, and I know HD temps are supposed to be forthcoming in 11.2, so it may be moot. I'd still love to hear some thoughts. Here's my command:

smartctl -a /dev/da0 | grep Temperature
smartctl -a /dev/da1 | grep Temperature
smartctl -a /dev/da2 | grep Temperature
smartctl -a /dev/da3 | grep Temperature
smartctl -a /dev/da4 | grep Temperature
smartctl -a /dev/da5 | grep Temperature
smartctl -a /dev/ada0 | grep Temperature
smartctl -a /dev/ada1 | grep Temperature
 

millst

Contributor
Joined
Feb 2, 2015
Messages
141
I've got something like that. It runs smartctl periodically and runs it through mrtg to generate graphs for past day, week, month, and year.

-tm
 

melloa

Wizard
Joined
May 22, 2016
Messages
1,749
I've never tried to write a script, but suspect there's a way to turn my command into a script that would run hourly and compile a database of historic hard drive temperatures

That might be the first of many you write. Try!

There are lots of scripts in the resource's tab and you can easily create one that does what you are looking for. Start small creating a log with the output of your commands, so you can manually import to a db; add as you go.

It will start with something like (change #!/bin/sh to reflect the shell you use):

Code:
#!/bin/sh


and define where your smartctl is ...

Code:
smartctl=/usr/local/sbin/smartctl


and a log for your temps ...

Code:
data_dir=/mnt/raid/scripts/hddtemp
log_file=$data_dir"/hddtemp.log"


(got to create /mnt/raid/scripts/hddtemp/hddtemp.log or won't work ;) Try touch)

and redirect the output of your commands above to the log file. Something like:

Code:
smartctl -a /dev/da0 | grep Temperature >> $log_file


the double > will add at the end of the file. You can either have one line per drive or, later, get fancy and use a loop; add a time stamp to each line, so you will have your history ... ;)

Don't forget to create a cron task to run it every X minutes.

Good luck!
 

millst

Contributor
Joined
Feb 2, 2015
Messages
141
After the grep, something like this should extract the raw temperature:

awk '{print $10}'

-tm
 

RichR

Explorer
Joined
Oct 20, 2011
Messages
77
I use this to track drive errors, but you could modify it for temps....

#! /bin/bash

for i in $(sysctl -n kern.disks)

do

echo "Disk $i"

smartctl -i -A /dev/$i |grep -E "^ "5"|^"187"|^"188"|^"197"|^"198""

done

echo "Done"
 
Status
Not open for further replies.
Top