voyeg3r

checkbattery.sh

Sep 27th, 2022 (edited)
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.71 KB | None | 0 0
  1. #!/bin/bash
  2. # File: /home/sergio/.dotfiles/bin/checkbattery.sh
  3. # Last Change: Mon, 26 Sep 2022 16:40:52
  4. #
  5. # https://www.2daygeek.com/linux-low-full-charging-discharging-battery-notification/
  6. # crontab example where you can use this script:
  7. # https://pastebin.com/Jn36y4sW
  8.  
  9. # removed loop because I am using a cronjob
  10. battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
  11. if [ $battery_level -ge 95 ]; then
  12.     notify-send "Battery Full" "Level: ${battery_level}%"
  13.     #paplay /usr/share/sounds/freedesktop/stereo/complete.oga
  14. elif [ $battery_level -le 20 ]; then
  15.     notify-send --urgency=CRITICAL "Battery Low" "Level: ${battery_level}%"
  16.     paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga
  17. fi
  18.  
  19.  
Advertisement
Add Comment
Please, Sign In to add comment