Skip to content

Instantly share code, notes, and snippets.

@alech
Created October 6, 2012 19:12
Show Gist options
  • Save alech/3845826 to your computer and use it in GitHub Desktop.
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
#!/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