Skip to content

Instantly share code, notes, and snippets.

@duk3luk3
Last active February 12, 2018 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duk3luk3/f04a9623add7ddfda8db724ee1890b86 to your computer and use it in GitHub Desktop.
Save duk3luk3/f04a9623add7ddfda8db724ee1890b86 to your computer and use it in GitHub Desktop.
Systemd Battery Monitor Service
# This file goes into /etc/systemd/system/battmon.service
[Unit]
Description=suspend when batt < 10%
[Service]
Type=oneshot
ExecStart=/usr/local/bin/battmon.sh
User=root
#!/bin/sh
# This file goes into /usr/local/bin/battmon.sh
acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
read -r status capacity
if [ "$status" = Discharging -a "$capacity" -lt 10 ]; then
logger "Critical battery threshold"
systemctl suspend
fi
}
# This file goes into /etc/systemd/system/battmon.timer
[Unit]
Description=Run battmon every minute
[Timer]
OnCalendar=minutely
Persistent=true
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment