Handle case where no rate information is available (e.g. when wireless mouse with acpi integration is plugged)

master
Lars Vierbergen 5 years ago
parent 334338f541
commit 7b331521a1
  1. 4
      battery-monitor.sh

@ -3,7 +3,7 @@ set -e
trap 'xmessage -nearmouse "WARNING: battery monitor died!"' EXIT trap 'xmessage -nearmouse "WARNING: battery monitor died!"' EXIT
was_notified=0 was_notified=0
while true; do while true; do
acpi_data=$(acpi -b) acpi_data=$(acpi -b | grep -v 'rate information unavailable' | head -n1)
status=$(echo -n "$acpi_data" | awk -F'[,:%]' '{print $2}') status=$(echo -n "$acpi_data" | awk -F'[,:%]' '{print $2}')
capacity=$(echo -n "$acpi_data" | awk -F'[,:%]' '{print $3}') capacity=$(echo -n "$acpi_data" | awk -F'[,:%]' '{print $3}')
echo "Status: $status; Capacity: $capacity; was_notified: $was_notified" echo "Status: $status; Capacity: $capacity; was_notified: $was_notified"
@ -15,7 +15,7 @@ while true; do
was_notified=1 was_notified=1
fi fi
if [[ "$status" =~ "Discharging" && "$capacity" -lt 10 ]]; then if [[ "$status" =~ "Discharging" && "$capacity" -lt 10 ]]; then
bash -c 'echo "Battery critical, suspending"; acpi -b' | xmessage -nearmouse -file -& echo -e "Battery critical, suspending\n$acpi_data" | xmessage -nearmouse -file -&
sleep 5 sleep 5
systemctl suspend systemctl suspend
sleep 600 # Wait 10 minutes, so we only hibernate once sleep 600 # Wait 10 minutes, so we only hibernate once

Loading…
Cancel
Save