From: Stefan Huber Date: Mon, 11 Nov 2024 16:37:24 +0000 (+0100) Subject: systemd: Fix battery script X-Git-Url: https://git.sthu.org/?a=commitdiff_plain;h=c0525d6944bc8e8d33964ccd32215ac5cc31c80d;p=shutils.git systemd: Fix battery script --- 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