Skip to content

Instantly share code, notes, and snippets.

@fawkesley
Last active May 23, 2022 01:27
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 fawkesley/525f87ee28537c404de57c8ef1459b15 to your computer and use it in GitHub Desktop.
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.
#!/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