Skip to content

Instantly share code, notes, and snippets.

@alkhachatryan
Last active November 29, 2020 20:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alkhachatryan/e98fd2b285601fa1a9311bbb980b8d18 to your computer and use it in GitHub Desktop.
Save alkhachatryan/e98fd2b285601fa1a9311bbb980b8d18 to your computer and use it in GitHub Desktop.
LINUX | Check the battery power
#!/bin/bash
#IF statment will use this var to notify user about low battery
LESS_THAN=70
#Interval in sec
INTERVAL=30
while true;
do
STR=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage)
VALUE=${STR//[A-Z a : %]/}
if [ $VALUE -lt $LESS_THAN ] ; then
notify-send "Battery is low: $VALUE%"
fi
sleep $INTERVAL;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment