Add 'pfsenseDellBatteryNUT.sh'

This commit is contained in:
2020-11-20 11:55:16 -05:00
parent 60a8167a3b
commit b10b0b543e

50
pfsenseDellBatteryNUT.sh Normal file
View File

@@ -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