blob: 9032b6d656eed70224dcc39e12c5657e77233141 [file] [log] [blame]
Venkata Srinivasa Raju Penmetcha686f6732012-02-01 22:31:371#!/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.
22TIME_IN_SECONDS=$1
23
24# Usage function.
25usage() {
26 cat <<EOF
27 $0 <time_in_seconds>
28 example: ./power_info.sh 300
29EOF
30exit 0
31}
32
33# Condition to check number of command line arguments.
34if [ $# != 1 ]; then
35 usage
36fi
37
38# Condition to check the given argument is number or not.
39if ! [ "$1" -eq "$1" 2> /dev/null ]
40 then
41 #echo "ERROR: Please provide number!" > /dev/stderr
42 usage
43fi
44
45true=1
46
47#Get current date and time.
48DATETIME="`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".
52FILENAME="Power_Info_${DATETIME}.log"
53
54#log and display results for the given time.
55while [ $true ]
56do
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
66done
67