Skip to content

Instantly share code, notes, and snippets.

@JGrossholtz
Created October 22, 2017 04:41
Show Gist options
  • Save JGrossholtz/87975101e86d9e6f39f13c3b965f6aa3 to your computer and use it in GitHub Desktop.
Save JGrossholtz/87975101e86d9e6f39f13c3b965f6aa3 to your computer and use it in GitHub Desktop.
Script that calculates average battery percentage for a laptop with 2 batteries
#!/bin/sh
# This script can be used to determine the average load of 2 batteries
# It requires the acpi command.
battA=$(acpi | grep "Battery \0" | cut -d" " -f 4 | sed "s/[^0-9]//g")
battB=$(acpi | grep "Battery 1" | cut -d" " -f 4 | sed "s/[^0-9]//g")
avg=$((($battA+$battB)/2))
if [ "$(acpi | grep "Discharging" | wc -l)" = 0 ]; then
echo [$avg%]
else
echo -e "$avg%"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment