Skip to content

Instantly share code, notes, and snippets.

@rrooij
Created August 12, 2019 17:01
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 rrooij/1a71defa9a3cc6f42dc6366d35b2b1da to your computer and use it in GitHub Desktop.
Save rrooij/1a71defa9a3cc6f42dc6366d35b2b1da to your computer and use it in GitHub Desktop.
Cron for checking battery life
#!/bin/sh
# Change BAT according to the battery you want to check
BATCAP=$(cat /sys/class/power_supply/BAT1/capacity)
WARNING_THRESHOLD=$1
export DISPLAY=:0
if [ -z "$WARNING_THRESHOLD" ]; then
WARNING_THRESHOLD=20
fi
if [ "$BATCAP" -lt "$WARNING_THRESHOLD" ]; then
notify-send "Low battery" "Battery at $BATCAP" -u critical
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment