Created
September 2, 2012 03:25
-
-
Save danielpclark/3594541 to your computer and use it in GitHub Desktop.
Hard drive temperature warning system with emergency shutdown. Run as cron job and save your computer system from a fatal overheating.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment