Difference between revisions of "CentOS 7.x laptop low battery alerts"
From Notes_Wiki
(Created page with "<yambe:breadcrumb>CentOS_7.x_laptop_battery|CentOS 7.x laptop battery</yambe:breadcrumb> =CentOS 7.x laptop low battery alerts= Create '<tt>~/bin/notify-send_setup</tt>' with...") |
m |
||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] > [[CentOS 7.x monitoring|Monitoring]] > [[CentOS 7.x laptop battery|Laptop battery]] > [[CentOS 7.x laptop low battery alerts]] | |||
Create '<tt>~/bin/notify-send_setup</tt>' with | Create '<tt>~/bin/notify-send_setup</tt>' with | ||
Line 51: | Line 50: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 7.x]] > [[CentOS 7.x monitoring|Monitoring]] > [[CentOS 7.x laptop battery|Laptop battery]] > [[CentOS 7.x laptop low battery alerts]] |
Latest revision as of 15:40, 28 August 2022
Home > CentOS > CentOS 7.x > Monitoring > Laptop battery > CentOS 7.x laptop low battery alerts
Create '~/bin/notify-send_setup' with
#!/bin/bash touch $HOME/.dbus/Xdbus chmod 600 $HOME/.dbus/Xdbus env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.dbus/Xdbus echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.dbus/Xdbus
Create '~/bin/battery-check' with
#!/bin/bash export DISPLAY=:0 XAUTHORITY=/home/saurabh/.Xauthority if [ -r "$HOME/.dbus/Xdbus" ]; then . "$HOME/.dbus/Xdbus" fi #BAT='upower -i /org/freedesktop/UPower/devices/battery_BAT0| grep -E "state|to\ full|percentage"' STATE=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep 'state' | sed 's/ *state: *//g' ) PERCENTAGE2=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep 'percentage' | sed 's/ *percentage: *//g' ) PERCENTAGE=$(echo $PERCENTAGE2 | sed 's/\%//g') if ( [[ "$STATE" != "charging" ]] && (( "$PERCENTAGE" < "35" )) ); then notify-send -u critical "Battery low" "Battery level is ${PERCENTAGE}%!" fi
Then edit crontab for user using "crontab -e" and add
*/5 * * * * sh /home/saurabh/bin/battery-check
Replace saurabh with your username appropriately. It is important to run this with current user.
Then /home/saurabh/bin/notify-send_setup must be executed once for every graphical login for things to work, so that ~/.dbus/Xdbus is configured correctly.
Refer:
Home > CentOS > CentOS 7.x > Monitoring > Laptop battery > CentOS 7.x laptop low battery alerts