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