public
Last active

Hard drive temperature warning system with emergency shutdown. Run as cron job and save your computer system from a fatal overheating.

  • Download Gist
hddwarner.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/ruby
 
# HDD Warner
# Author: Daniel P. Clark
# webmaster@6ftdan.com
# License: MIT <http://opensource.org/licenses/mit-license.php>
# Date: August 31st, 2012
 
=begin
The MIT License (MIT)
 
Copyright (c) <year> <copyright holders>
 
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
=end
 
 
# DEPENDENCIES
# libnotify-bin, hddtemp (daemon)
 
require 'net/telnet'
 
webserver = Net::Telnet::new('Host' => "127.0.0.1",
'Port' => "7634",
'Telnetmode' => false)
 
size = 0
 
temps = webserver.cmd("GET")
sda,sdb = temps.split('||')
sda = sda.split('|').reject { |c| c.empty? }
sdb = sdb.split('|').reject { |c| c.empty? }
#printf "DEVICE: %s MODEL: %s CURRENT TEMP: %s%s\n" % sda
#printf "DEVICE: %s MODEL: %s CURRENT TEMP: %s%s\n" % sdb
 
def toF(c)
return c*9/5+32
end
 
if File.exists?('/usr/bin/notify-send')
if sda[2].to_i == 45 or sdb[2].to_i == 45 or sda[2].to_i == 46 or sdb[2].to_i == 46
`/usr/bin/notify-send -u normal HDD_HEAT_WARNING 'Hard Drive is Hot!\nSDA is #{sda[2..3].join(" ")} / #{toF(sda[2].to_i)} F\nSDB is #{sdb[2..3].join(" ")} / #{toF(sdb[2].to_i)} F'`
elsif sda[2].to_i == 47 or sdb[2].to_i == 47
`/usr/bin/notify-send -u critical HDD_CRITICAL_HEAT 'Preparing to Shut System Down!\nSDA is #{sda[2..3].join(" ")} / #{toF(sda[2].to_i)} F\nSDB is #{sdb[2..3].join(" ")} / #{toF(sdb[2].to_i)} F'`
elsif sda[2].to_i >= 48 or sdb[2].to_i >= 48
`/usr/bin/notify-send -u critical HDD_HEAT_SHUTTING_DOWN 'Powering Down Now!\nSDA is #{sda[2..3].join(" ")} / #{toF(sda[2].to_i)} F\nSDB is #{sdb[2..3].join(" ")} / #{toF(sdb[2].to_i)} F'`
end
end
 
if sda[2].to_i >= 48 or sdb[2].to_i >= 48
sleep(4)
`shutdown -h now`
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.