#!/bin/bash help () { cat < or system shutdown. ## ## Output can be collected into logfiles to profile a battery. ## ## ## ## Usage: tty1$ chargecycle [-tT] ## ## ## ## Options: -b show battery info only (default) ## ## Options: -t show battery and thermal info ## ## Options: -T show only thermal info ## ## Options: -h show this help message and exit ## ## ## ## Suggested usage: tty1$ chargecycle | tee chargelog.txt ## ## ## ########################################################################### EOT exit 0 } ## Initialize variable to default values, then parse command ine arguements. arg=-b help=0 while getopts :htTb opt do case $opt in h ) help=1 ;; \? ) help=1 ;; b ) arg=-b ;; t ) arg=-t ;; T ) arg=-tB ;; esac done ## If -h flag is set post usage information and exit. if [ $help = 1 ] then help fi ## Test if acpi is available, post error message and exit if not. if [ ! $(which acpi 2>/dev/null) ] then echo "Advanced Configuration Power Interface (acpi) program or kernel module not installed." exit 1 fi ## Test if a battery is present, post error message and exit if not. if (acpi -b 2>&1 | grep "No support for device type: battery" >/dev/null ) then echo "chargecycle: This system has no battery. Running this program makes no sense here." exit fi ## Commence loop to get and time stamped report acpi information. while true do echo -n "$(date +%m-%d-%Y-%T) " echo $(acpi $arg)| sed s/information/info/g sleep 120; done