I am trying to make a script that will conntect to a ups and get the battery value and store it in a variable.
I have managed to connect to the ups and get infomation from it but I am strugling to get just the battery value into a variable.
Script so far
#!/bin/bash
#
# Connect to ups and output values into output var
output="$( upsc ups@localhost)"
# Trip the output to just have battery charge info
output1="$( sed -n '/battery.charge:*/,/./p' <<< "$output" )"
echo "$output1";
Output returns
ambient.1.humidity.alarm.high: 60.00
ambient.1.humidity.alarm.low: 30.00
ambient.1.temperature.alarm.high: 40.00
ambient.1.temperature.alarm.low: 10.00
battery.charge: 100.00
battery.current: 0.00
battery.current.total: 0.00
battery.date: 03/15/2013
battery.runtime: 2040.00
battery.runtime.low: 120
battery.voltage: 54.70
device.mfr: APC
device.model: Smart-UPS 2200
device.serial: IS1248007101
device.type: ups
driver.name: snmp-ups
driver.parameter.pollinterval: 2
driver.parameter.port: 172.16.27.207
driver.version: 2.7.2
driver.version.data: apcc MIB 1.2
driver.version.internal: 0.72
input.frequency: 50.00
input.sensitivity: high
input.transfer.high: 253
input.transfer.low: 208
input.transfer.reason: smallMomentarySpike
input.voltage: 249.00
input.voltage.maximum: 249.00
input.voltage.minimum: 247.50
output.current: 2.30
output.frequency: 50.00
output.voltage: 249.00
output.voltage.nominal: 230
ups.delay.shutdown: 0
ups.delay.start: 0
ups.firmware: UPS 06.5 / MCU 11.0 / UBL 08.2 / MBL 11.0 (ID18)
ups.id: UPS-Understage
ups.load: 25.30
ups.mfr: APC
ups.mfr.date: 11/24/2012
ups.model: Smart-UPS 2200
ups.serial: IS1248007101
ups.status: OL
ups.temperature: 18.30
ups.test.date: 04/12/2016
ups.test.result: Ok
I just need that part that says battery.charge: 100.00
into a variable
With the script how it is I get an output of
battery.charge: 100.00
battery.current: 0.00
Any help please just to get 100.00 from the battery.charge bit.
battery.charge
usingupsc battery.charge