Skip to content

Instantly share code, notes, and snippets.

@yunazuno
Created December 7, 2011 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunazuno/1441153 to your computer and use it in GitHub Desktop.
Save yunazuno/1441153 to your computer and use it in GitHub Desktop.
Log the battery stete to a file
#!/bin/sh
# Log the battery stete to a file
# Sources of battery information
PROC_INFO='/proc/acpi/battery/BAT0/info'
PROC_STATE='/proc/acpi/battery/BAT0/state'
# Get the current state
type=`grep "model number:" $PROC_INFO | awk -e '{print $3}'`
current=`grep "remaining capacity:" $PROC_STATE | awk -e '{print $3}'`
last_full=`grep "last full capacity:" $PROC_INFO | awk -e '{print $4}'`
# Save to the file
output=$HOME/.battery_$type.log
id=`touch $output && wc -l $output | awk -e '{print $1}'`
datetime=`date +%Y%m%d%H%M%S`
line="$id $datetime $last_full $current"
echo $line >> $output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment