]> git.sthu.org Git - shutils.git/commitdiff
systemd: Fix battery script
authorStefan Huber <shuber@sthu.org>
Mon, 11 Nov 2024 16:37:24 +0000 (17:37 +0100)
committerStefan Huber <shuber@sthu.org>
Mon, 11 Nov 2024 16:37:24 +0000 (17:37 +0100)
systemd/usr/lib/systemd/system-sleep/battery

index 87303719850a3f26b670c71af385cd8351b856f1..17cdf3e20f4127e7371bfc001e8a6ae67d967d54 100755 (executable)
@@ -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