Already corrected the code in the post.
Once he is improving, updating here and I will accept suggestions.
]]>If you see the "one minute warning" and plug the charger in, BATTERY_STATUS is still set to "Discharging" so it will always shutdown. You need to read BATTERY_STATUS again after "sleep 60".
edit: probably also need == rather than =
]]>#!/usr/bin/bash
BATTERY_CAPACITY=$(cat /sys/class/power_supply/BAT0/capacity)
BATTERY_STATUS=$(cat /sys/class/power_supply/BAT0/status)
SHUTDOWN_WITH=3
NOTIFY_TITLE="Bateria Fraca"
NOTIFY_ICON=battery_empty
NOTIFY_MESSAGE="Seu computador serĂ¡ desligado em 1 minuto."
WM=gnome-shell
WMPID=$(pidof ${WM})
WMUSER=$(ps -e -o user,comm | grep ${WM} | cut -f1 -d " ")
DBUS=$(egrep -z 'DBUS_SESSION_BUS_ADDRESS|DISPLAY' /proc/${WMPID}/environ | sed -r -e 's/(.)DBUS_/\1 DBUS_/' -e 's/(.)DISPLAY/\1 DISPLAY/')
if [[ $BATTERY_CAPACITY -le $SHUTDOWN_WITH && $BATTERY_STATUS = "Discharging" ]]; then
/bin/su ${WMUSER} -c "${DBUS} notify-send --urgency=critical --hint=int:transient:1 --icon $NOTIFY_ICON '$NOTIFY_TITLE' '$NOTIFY_MESSAGE'"
sleep 60s
BATTERY_STATUS=$(cat /sys/class/power_supply/BAT0/status)
if [[ $BATTERY_STATUS = "Discharging" ]]; then
systemctl poweroff
fi
fi
After I saved in /usr/bin as battery_monitor and scheduled cron with the following line
*/2 * * * * /usr/bin/battery_monitor
I hope it is useful.
]]>#!/bin/bash
BATTINFO=`acpi -b`
if [[ `echo $BATTINFO | grep Discharging` && `echo $BATTINFO | cut -f 5 -d " "` < 00:15:00 ]] ; then
DISPLAY=:0.0 /usr/bin/notify-send "low battery" "$BATTINFO"
fi
I don't know if "acpi -b" gives the same format for all devices, mine is an Acer 5742Z.
Rather than acpi, I'd probably use info from /sys/class/power_supply/BAT0/* if I was using it now.
]]>I do not want large configurations, now my battery lasts around 3 hours without any effort, I just really want to shutdown on low battery.
Thanks.
EDIT: Analyzing various forum posts, I realized that neither acpid_listen nor udevadm - monitor receiving a trigger for battery. Anyone have any suggestions?
]]>