134 lines
4.4 KiB
Bash
134 lines
4.4 KiB
Bash
#!/bin/sh
|
|
|
|
# NUT dummpyUPS driver file location
|
|
FILE_LOCATION='/root/laptopbattery.dev'
|
|
|
|
# get battery stats from the apm command
|
|
BATTERY_PERCENT_LEVEL=$(acpiconf -i batt# | awk '/Remaining capacity:/ {print $3}'| sed -e 's/\%//')
|
|
BATTERY_DESIGNED_CAPACITY=$(acpiconf -i batt# | awk '/Design capacity:/ {print ($3 / 1000)}')
|
|
BATTERY_LAST_FULL_CAPACITY=$(acpiconf -i batt# | awk '/Last full capacity:/ {print ($4 / 1000)}')
|
|
BATTERY_WEAR_PERCENT=$(echo "scale=2; 100 * ${BATTERY_LAST_FULL_CAPACITY} / ${BATTERY_DESIGNED_CAPACITY}" | bc -l)
|
|
BATTERY_CURRENT=$(acpiconf -i batt# | awk '/Present rate:/ {print ($3 / 1000)}')
|
|
UPS_MFR=$(acpiconf -i batt# | awk '/Model number:/ {print $3}')
|
|
UPS_MODEL=$(acpiconf -i batt# | awk '/Model number:/ {print $3" "$4}')
|
|
UPS_SERIAL=$(acpiconf -i batt# | awk '/Serial number:/ {print $3}')
|
|
UPS_VOLTAGE=$(acpiconf -i batt# | awk '/Present voltage:/ {print ($3 / 1000)}')
|
|
BATTERY_STATE=$(acpiconf -i batt# | awk '/State:/ {print $2}')
|
|
BATTERY_RUNTIME=$(acpiconf -i batt# | awk '/Remaining time:/ {print $3}')
|
|
|
|
if [ ${BATTERY_STATE} = 'discharging' ]; then
|
|
BATTERY_RUNTIME=$(echo ${BATTERY_RUNTIME} | awk -F: '{ print ($1 * 3600) + ($2 * 60) }')
|
|
if [ ${BATTERY_PERCENT_LEVEL} > 25 ]; then
|
|
BATTERY_STATE='OB'
|
|
else
|
|
BATTERY_STATE='LB'
|
|
fi
|
|
elif [ ${BATTERY_STATE} = 'charging' ]; then
|
|
BATTERY_STATE='CHRG'
|
|
elif [ ${BATTERY_STATE} = 'high' ]; then
|
|
BATTERY_STATE='OL'
|
|
if [ ${BATTERY_WEAR_PERCENT} <= 25 ]; then
|
|
BATTERY_STATE='RB'
|
|
fi
|
|
fi
|
|
|
|
echo "# Last Updated: $(date)" > ${FILE_LOCATION}
|
|
echo "battery.charge: ${BATTERY_PERCENT_LEVEL}" >> ${FILE_LOCATION}
|
|
echo "battery.runtime: ${BATTERY_RUNTIME}" >> ${FILE_LOCATION}
|
|
echo "ups.mfr: ${UPS_MFR}" >> ${FILE_LOCATION}
|
|
echo "ups.model: ${UPS_MODEL}" >> ${FILE_LOCATION}
|
|
echo "ups.serial: ${UPS_SERIAL}" >> ${FILE_LOCATION}
|
|
echo "ups.status: ${BATTERY_STATE}" >> ${FILE_LOCATION}
|
|
echo "battery.voltage: ${UPS_VOLTAGE}" >> ${FILE_LOCATION}
|
|
echo "battery.capacity: ${BATTERY_LAST_FULL_CAPACITY}" >> ${FILE_LOCATION}
|
|
echo "battery.designedCapacity: ${BATTERY_DESIGNED_CAPACITY}" >> ${FILE_LOCATION}
|
|
echo "battery.wear: ${BATTERY_WEAR_PERCENT}" >> ${FILE_LOCATION}
|
|
echo "battery.current: ${BATTERY_CURRENT}" >> ${FILE_LOCATION}
|
|
|
|
:'
|
|
battery.charge: 79
|
|
ups.mfr: Dell
|
|
ups.model: Laptop Battery
|
|
ups.serial:
|
|
ups.status: LB
|
|
battery.runtime: 10009
|
|
battery.charge.low: 20
|
|
battery.charge.warning: 35
|
|
battery.voltage:
|
|
battery.capacity Battery capacity (Ah) 7.2
|
|
battery.current Battery current (A)
|
|
OL: On line (no power failure)
|
|
OB: On battery
|
|
LB: Low battery
|
|
SD: Shutdown load
|
|
|
|
APM on battery:
|
|
APM version: 1.2
|
|
APM Management: Disabled
|
|
AC Line status: off-line
|
|
Battery Status: high
|
|
Remaining battery life: 71%
|
|
Remaining battery time: 4:52:00
|
|
Number of batteries: 1
|
|
Battery 0:
|
|
Battery Status: high
|
|
Remaining battery life: 71%
|
|
Remaining battery time: 4:52:00
|
|
Resume timer: unknown
|
|
Resume on ring indicator: disabled
|
|
|
|
|
|
acpiconf -i batt# on battery:
|
|
Design capacity: 7894 mAh
|
|
Last full capacity: 6015 mAh
|
|
Technology: secondary (rechargeable)
|
|
Design voltage: 7600 mV
|
|
Capacity (warn): 789 mAh
|
|
Capacity (low): 239 mAh
|
|
Low/warn granularity: 78 mAh
|
|
Warn/full granularity: 78 mAh
|
|
Model number: DELL 2X39G74
|
|
Serial number: 3401
|
|
Type: LION
|
|
OEM info: LGC-LGC7.780
|
|
State: discharging
|
|
Remaining capacity: 71%
|
|
Remaining time: 4:50
|
|
Present rate: 885 mA (6835 mW)
|
|
Present voltage: 7724 mV
|
|
|
|
apm charging:
|
|
APM version: 1.2
|
|
APM Management: Disabled
|
|
AC Line status: on-line
|
|
Battery Status: charging
|
|
Remaining battery life: 71%
|
|
Remaining battery time: unknown
|
|
Number of batteries: 1
|
|
Battery 0:
|
|
Battery Status: charging
|
|
Remaining battery life: 71%
|
|
Remaining battery time: unknown
|
|
Resume timer: unknown
|
|
Resume on ring indicator: disabled
|
|
|
|
|
|
acpiconf -i batt# charging:
|
|
Design capacity: 7894 mAh
|
|
Last full capacity: 6015 mAh
|
|
Technology: secondary (rechargeable)
|
|
Design voltage: 7600 mV
|
|
Capacity (warn): 789 mAh
|
|
Capacity (low): 239 mAh
|
|
Low/warn granularity: 78 mAh
|
|
Warn/full granularity: 78 mAh
|
|
Model number: DELL 2X39G74
|
|
Serial number: 3401
|
|
Type: LION
|
|
OEM info: LGC-LGC7.780
|
|
State: charging
|
|
Remaining capacity: 71%
|
|
Remaining time: unknown
|
|
Present rate: 1 mA (7 mW)
|
|
Present voltage: 7821 mV
|
|
' |