Venkata Srinivasa Raju Penmetcha | 686f673 | 2012-02-01 22:31:37 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | ############################################################################### |
| 8 | # |
| 9 | # This script can be used to check the current battery or AC status. |
| 10 | # It also logs and disply the results for the given time interval. |
| 11 | # ( Ref: 22430 in chromium-os). |
| 12 | # |
| 13 | # Command syntax: |
| 14 | # ./power_info.sh time_in_seconds. |
| 15 | # |
| 16 | # Example: |
| 17 | #./power_info.sh 600 (10 minutes). |
| 18 | # |
| 19 | ############################################################################### |
| 20 | |
| 21 | # User definied flags. |
| 22 | TIME_IN_SECONDS=$1 |
| 23 | |
| 24 | # Usage function. |
| 25 | usage() { |
| 26 | cat <<EOF |
| 27 | $0 <time_in_seconds> |
| 28 | example: ./power_info.sh 300 |
| 29 | EOF |
| 30 | exit 0 |
| 31 | } |
| 32 | |
| 33 | # Condition to check number of command line arguments. |
| 34 | if [ $# != 1 ]; then |
| 35 | usage |
| 36 | fi |
| 37 | |
| 38 | # Condition to check the given argument is number or not. |
| 39 | if ! [ "$1" -eq "$1" 2> /dev/null ] |
| 40 | then |
| 41 | #echo "ERROR: Please provide number!" > /dev/stderr |
| 42 | usage |
| 43 | fi |
| 44 | |
| 45 | true=1 |
| 46 | |
| 47 | #Get current date and time. |
| 48 | DATETIME="`date '+%d%m%y_%H%M%S'`" |
| 49 | |
| 50 | #File Name will be appended with current date and time. |
| 51 | #The format of the file name is "Power_Info_DDMMYY_HHMMSS.log". |
| 52 | FILENAME="Power_Info_${DATETIME}.log" |
| 53 | |
| 54 | #log and display results for the given time. |
| 55 | while [ $true ] |
| 56 | do |
| 57 | # Get online, state and percentage values from power-supply-info script, |
| 58 | # then display and redirect to a file (Power_Info_DDMMYY_HHMMSS.log). |
| 59 | /usr/bin/power-supply-info | egrep '(online|state|percentage)' 2>&1 | tee -a $FILENAME |
| 60 | #log and display current time |
| 61 | time=`date +%H:%M:%S` |
| 62 | echo " Time: $time" 2>&1 | tee -a $FILENAME |
| 63 | echo " " 2>&1 | tee -a $FILENAME |
| 64 | #sleep till the given time elapses. |
| 65 | sleep $TIME_IN_SECONDS |
| 66 | done |
| 67 | |