Created
October 6, 2012 19:12
-
-
Save alech/3845826 to your computer and use it in GitHub Desktop.
little hack to suspend when battery is low or temperature is too high
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/env ruby | |
a = `acpi` | |
if a[/Discharging/] then | |
# battery is discharging, check if we are below 3% | |
perc = a[/(\d+)%/, 1] | |
if perc.to_i <= 3 then | |
log = open '/tmp/debuglog', 'w' | |
log.puts "Battery discharging, percentage <= 3" | |
log.close | |
`sudo pm-suspend` | |
end | |
end | |
t = `sensors acpitz-virtual-0 -u|grep temp1_input` | |
temp = t[/: (\d+)/, 1] | |
if temp.to_i >= 94 then | |
log = open '/tmp/debuglog', 'w' | |
log.puts "Temperature >= 94" | |
log.close | |
`sudo pm-suspend` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment