More changes
This commit is contained in:
parent
d411d8b3b5
commit
3e36fb9979
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
# battery-monitor.sh
|
# battery-monitor.sh
|
||||||
|
|
||||||
# This program lets the user know when the battery needs to be charged, and
|
# Once a user defined minimum is reached, this program lets the user know
|
||||||
# suspends the computer once a user defined minimum is reached. It has been
|
# when the battery needs to be charged and suspends the computer.
|
||||||
# tested to work on a Debian 12 GNU/Linux x86_64 default console
|
|
||||||
# installation. The installation of bc is required.
|
# This program has been verified to work on a Debian 12 GNU/Linux x86_64
|
||||||
|
# default console installation, but the installation of the bc program is
|
||||||
|
# required.
|
||||||
|
|
||||||
# Copyright (c) 2024, Scott C. MacCallum (scott@scm-guru.live).
|
# Copyright (c) 2024, Scott C. MacCallum (scott@scm-guru.live).
|
||||||
|
|
||||||
@ -28,7 +30,7 @@
|
|||||||
# Change this variable to the group that should be informed of a need to
|
# Change this variable to the group that should be informed of a need to
|
||||||
# charge the battery. On GNU/Linux distributions users are often part of
|
# charge the battery. On GNU/Linux distributions users are often part of
|
||||||
# a group that is the same as their login name, which works well if you only
|
# a group that is the same as their login name, which works well if you only
|
||||||
# want your user to be informed in the console.
|
# want your user to be informed on the console.
|
||||||
|
|
||||||
group="scm"
|
group="scm"
|
||||||
|
|
||||||
@ -42,6 +44,8 @@ if (( minutes == 0 )); then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Calculate the state of the battery.
|
||||||
|
|
||||||
charge=$(cat /sys/class/power_supply/$battery/charge_now)
|
charge=$(cat /sys/class/power_supply/$battery/charge_now)
|
||||||
discharge=$(cat /sys/class/power_supply/$battery/current_now)
|
discharge=$(cat /sys/class/power_supply/$battery/current_now)
|
||||||
hours=$(echo "scale=2; $charge / $discharge" | bc -l)
|
hours=$(echo "scale=2; $charge / $discharge" | bc -l)
|
||||||
@ -49,20 +53,19 @@ minutes=$(echo "scale=2; $hours * 60" | bc -l)
|
|||||||
|
|
||||||
# Change the minimum variable to the minimum amount of minutes that a battery
|
# Change the minimum variable to the minimum amount of minutes that a battery
|
||||||
# is estimated to have left before the group is informed to recharge it. When
|
# is estimated to have left before the group is informed to recharge it. When
|
||||||
# I tested this and the battery-suspend.sh script, I was surprised to
|
# I tested this, I was surprised to discover that the computer turned off
|
||||||
# discover that the computer turned off despite having reported that there
|
# despite having reported that there was 10 minutes left! I created the
|
||||||
# was 10 minutes left! I created the battery-status.sh script to aid in my
|
# battery-status.sh script to aid in my understanding of what was going on,
|
||||||
# understanding of what was going on, and I discovered a variance of about 10
|
# and I discovered a variance of minutes plus/minus each time that I ran it,
|
||||||
# minutes plus/minus each time that I ran it, so the system is clearly making
|
# so the system is clearly making an estimate. Keep this in mind when setting
|
||||||
# an estimate. Keep the minus 10 minutes in mind when setting the minimum
|
# the minimum value.
|
||||||
# value.
|
|
||||||
|
|
||||||
# Change this variable to you liking, but less than 40.00 is likely a bad
|
# Change this variable to you liking, but less than 40.00 is likely a bad
|
||||||
# idea. YOU'VE BEEN WARNED!
|
# idea. YOU'VE BEEN WARNED!
|
||||||
|
|
||||||
minimum=40.00
|
minimum=40.00
|
||||||
|
|
||||||
If the minutes of charge are less that the minimum.
|
If the minutes of charge are less than the minimum.
|
||||||
|
|
||||||
if (( $(echo "$minutes < $minimum" | bc -l) )); then
|
if (( $(echo "$minutes < $minimum" | bc -l) )); then
|
||||||
echo "Suspending the computer! Battery charge is needed!" | wall -g $group
|
echo "Suspending the computer! Battery charge is needed!" | wall -g $group
|
||||||
|
Loading…
x
Reference in New Issue
Block a user