I just bought a Back-UPS.

So that if there is a power outage, this serves as some sort of a backup power.

I have set it up. It works, even when I plug it out.

But what I want to happen, is that the computer connected to it, will run maybe a cron job every ten minutes, to see how much battery is remaining, and if its below, say, 30%. Then it implements a proper shutdown.

But I can't seem to find, how to determine programmatically, how much power is left on the ups.

Does anybody know how to get that information?

  • idk that one specifically, but they normally can tell the computer over USB to shut down gracefully when they're running out of power.
    – Tetsujin
    Aug 30 at 11:19
  • 2
    Why bother rolling your own? Use apcupsd instead.
    – Daniel B
    Aug 30 at 11:20
  • I was just going to suggest apcupsd.org as well. I used it for several years on a server that didn't support APC's client software and it worked very well. And you get the source code, if it doesn't quite meet your needs. Aug 30 at 11:21
  • I have a similar unit in the basement. After 10 minutes, you need to shut down all computers (or the UPS may do that for you). 10 -15 minutes is all you get for non-battery powered computers. After that, laptops and network (modem, router) should go longer.
    – John
    Aug 30 at 12:34
  • why bother? this apcupsd seems to be a huge bother. and nut is crazy difficult to setup as well.
    – john-jones
    Aug 30 at 17:49

1 Answer 1


the upc is just plugged to the computer via electric plugin

You'll need to additionally plug it in to the computer via USB. There's a USB port somewhere on the UPS – hopefully standard Type-B these days, though APC has been known to use weird RJ45-ish (10P10C?) connectors for USB. Some other UPS types use a RS232 serial port.

Once the UPS shows up in lsusb (likely as some kind of serial or HID device), install some software that can talk to it. For APC specifically, apcupsd seems to be common; APC is also one of the many UPS types supported by nut (Network UPS Tools).

I've only ever used the latter software, but it has the upsc command to interrogate the UPS-monitor daemon about battery state (and many more parameters); I assume apcupsd has something similar, as that's kind of the whole point.

Most likely you won't even need a cronjob – the UPS monitoring software almost always has preemptive shutdown built-in.

  • im trying to install nut, going by directions here zackreed.me/installing-nut-on-ubuntu. the second command to change, /etc/nut/ups.conf. gives me permission error. i could sudo, but that creates problems later. do you know how i should proceed with this?
    – john-jones
    Aug 30 at 15:18
  • @john-jones - Sounds like a question that has an answer that can’t fit in a comment
    – Ramhound
    Aug 31 at 1:44
  • sudo creates problems if you sudo the wrong things. There's a time when you need to use sudo and there's a time when you don't. If you need to edit a file that is in /etc and is owned by root, then you need root privileges, whether you obtain them via sudo or otherwise. Aug 31 at 4:07
  • yes and i don't have any choice for the document tells me to edit a file, which i don't have permission to edit without sudo.
    – john-jones
    Aug 31 at 10:43
  • Then edit it with sudo? Aug 31 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .