From b10b0b543e39e279379af611d6615d042d67ed9f Mon Sep 17 00:00:00 2001 From: jgaunt Date: Fri, 20 Nov 2020 11:55:16 -0500 Subject: [PATCH] Add 'pfsenseDellBatteryNUT.sh' --- pfsenseDellBatteryNUT.sh | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pfsenseDellBatteryNUT.sh diff --git a/pfsenseDellBatteryNUT.sh b/pfsenseDellBatteryNUT.sh new file mode 100644 index 0000000..9192442 --- /dev/null +++ b/pfsenseDellBatteryNUT.sh @@ -0,0 +1,50 @@ +#!/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/\%//') +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}') # will be unknown or something like 5:22 + +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='OL' +fi + + +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} + + + +#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: + +#OL: On line (no power failure) +#OB: On battery +#LB: Low battery +#SD: Shutdown load \ No newline at end of file