Last active
May 23, 2022 01:27
-
-
Save fawkesley/525f87ee28537c404de57c8ef1459b15 to your computer and use it in GitHub Desktop.
poweroffat80percent.sh - wait for laptop battery to drain to 80% then power off. save battery lifetime.
This file contains hidden or 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 -eu | |
while true | |
do | |
sudo whoami > /dev/null | |
BATT_PERCENT=$(cat /sys/class/power_supply/BAT0/capacity) | |
if [ "$BATT_PERCENT" -le "80" ]; then | |
echo "battery ${BATT_PERCENT}%. powering off now." | |
break | |
else | |
echo "battery ${BATT_PERCENT}%. waiting till < 80%" | |
fi | |
sleep 30s | |
done | |
/usr/bin/poweroff | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment