Last active
February 12, 2018 10:48
-
-
Save duk3luk3/f04a9623add7ddfda8db724ee1890b86 to your computer and use it in GitHub Desktop.
Systemd Battery Monitor Service
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
# 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 |
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
#!/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 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
# 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