If you are running in the text mode and want to find out if your laptop is running on battery or on ac power you can use the command "on_ac_power".
The command returns "0" if laptop is running on ac power, 1 if it is runnning on battery and 255 if it can not determine.
For eg:
$ ac_on_power
$ echo $?
0
Thus the laptop is running on ac power.
You can use the following script to make the output look more user friendly.
#!/bin/bash
on_ac_power
if [ $? -eq 0 ]
then
echo "Running on ac power"
elif [ $? -eq 1 ]
then
echo "Running on Battery"
else
echo "Can not detemine"
fi
Save the script as power.sh and run it as follows.
$ sh power.sh
Running on ac power
Thus giving the required information in more readable format.
No comments:
Post a Comment