Created
August 6, 2021 12:34
-
-
Save eze-kiel/f0b4ede024791271ba539ce9fa444af8 to your computer and use it in GitHub Desktop.
Bash script that notify if the battery level is too low. Initially made for a cronjob
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/bash | |
STATE=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | head -n 12 | tail -n1 | awk '{print $2}') | |
if [ "$STATE" == "charging" ]; then | |
exit 0 | |
fi | |
PERCENT=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | head -n 21 | tail -n1 | awk '{print $2}' | cut -d '%' -f1) | |
if [ $PERCENT -lt 20 ]; then | |
export DISPLAY=:0 | |
/usr/bin/notify-send -u critical "Battery is low ($PERCENT)%" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Corresponding cronjob:
*/2 * * * * /path/to/batt_percentage.sh
This will execute the script every 2 minutes.