From c0525d6944bc8e8d33964ccd32215ac5cc31c80d Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 11 Nov 2024 17:37:24 +0100 Subject: [PATCH] systemd: Fix battery script --- systemd/usr/lib/systemd/system-sleep/battery | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/systemd/usr/lib/systemd/system-sleep/battery b/systemd/usr/lib/systemd/system-sleep/battery index 8730371..17cdf3e 100755 --- a/systemd/usr/lib/systemd/system-sleep/battery +++ b/systemd/usr/lib/systemd/system-sleep/battery @@ -3,22 +3,22 @@ acpi=$(acpi) date=$(date -Iseconds --utc) -addendum="" +addendum="." if [ "$1" = "post" ]; then lastpre=$(grep pre /var/log/batterstat.log | tail -n1) if [ ! -z "${lastpre}" ]; then - preprecent=$(echo "${lastpre}" | cut -f2 -d, | cut -f1 -d% | awk '{ print $1 }') - predate=$(echo "${lastpre}" | grep -o " at .*" | awk '{ print $2 }') + prepercent=$(echo "${lastpre}" | grep -o "[0-9]*%" | cut -f1 -d%) + predate=$(echo "${lastpre}" | awk '{ print $1 }') - postpercent=$(echo "${acpi}" | cut -f2 -d, | cut -f1 -d% | awk '{ print $1 }') + postpercent=$(echo "${acpi}" | grep -o "[0-9]*%" | cut -f1 -d%) let diffmin=($(date +%s -d ${date})-$(date +%s -d ${predate}))/60 - let diffperc=(prepercent-postprecent) + let diffperc=(prepercent-postpercent) - addendum=", discharged ${diffperc}% (${preprecent}% -> ${postpercent}%) in ${diffmin} minutes" + addendum="${addendum} Discharged ${diffperc}% (${prepercent}% -> ${postpercent}%) in ${diffmin} minutes." fi fi -echo "$1: ${acpi} at ${date}${addendum}" >> /var/log/batterstat.log +echo "${date} $1: ${acpi}${addendum}" >> /var/log/batterstat.log -- 2.39.5