Skip to content

Instantly share code, notes, and snippets.

@hurricup
Last active October 29, 2021 20:06
Show Gist options
  • Save hurricup/8389cedba025e5f3aa498ef5a4ac2e83 to your computer and use it in GitHub Desktop.
Save hurricup/8389cedba025e5f3aa498ef5a4ac2e83 to your computer and use it in GitHub Desktop.
Script for logging voltage using UPS device and Network UPS tools
#!/bin/bash
previous_filename="none"
previous_voltage=-1
while true
do
filename=$(date "+%Y-%m-%d")
upsinfo=$(upsc powercom 2>/dev/null |grep 'input.voltage:')
voltage=${upsinfo#input.voltage: }
voltage=${voltage%.0}
if [ $previous_filename != $filename ] || [ $voltage != $previous_voltage ]
then
date=$(date "+%H:%M:%S")
echo -e $date"\t"$voltage >> ~/powerlogs/$filename.csv
previous_filename=$filename
previous_voltage=$voltage
fi
sleep 1
done
@hurricup
Copy link
Author

Requires:

  1. UPS with data channel
  2. https://github.com/networkupstools/nut/ installed and supports UPS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment