4 ms·
The headline is a bit misleading. I thought it meant it was about triggering a command on a computer that has no power, which is obviously impossible. What it’
by Apreche 1y ago
The headline is a bit misleading. I thought it meant it was about triggering a command on a computer that has no power, which is obviously impossible.
What it’s actually about how to automatically automatically trigger a command on a Linux computer (almost certainly a laptop) in the event that it switches from AC power to battery power.
The example given is your laptop is plugged it at a café. Someone steals it, which involves unplugging it from the wall. At the moment it is unplugged it automatically shuts down, locks itself, etc.
I wonder if the same approach will also work for a computer connected to a UPS. Probably not!
- nisegami 1y agoComputers connected a UPS can use tools like NUT or more specific tools like apcupsd. It's much more common to need to know when a UPS powered device switches to battery to trigger stuff than it is to need to know when a laptop switches to battery, so there's a lot more tooling in that area.
- netsharc 1y agoMaybe you know this, but UPSs have signaling software to tell whomever it may concern if it has lost power and is running on battery. For big servers, the UPS's batteries might only give minutes of power, so they'd listen for such a signal to do an orderly shutdown.
- LoganDark 1y ago"on power disconnection" (event) probably would've worked better than "when disconnected from power" (time period).
- 1718627440 1y agoThat's exactly how I understood the headline.
- Rooster61 1y ago+1 to this. This is still a logical use case, but it's not the mental image that immediately got conjured up after reading the title for me.
- NooneAtAll3 1y ago+1?
- Rooster61 1y agoYes, thank you. Fatfingered
- wkjagt 1y agoIt's a way of signaling agreement.
- Rooster61 1y agoThey were correcting my initial "1+"
- tenthirtyam 1y agoShouldn't we programmers be just typing "++"?
- yndoendo 1y agoi++
- wildzzz 1y agoWith that example, why not just remove the battery entirely? As for a UPS, I have a Synology NAS that can monitor an APC UPS over its serial USB port. When the UPS loses power or is told to gracefully shutdown, the NAS also gracefully shuts down.
- piperswe 1y ago> I wonder if the same approach will also work for a computer connected to a UPS. Probably not! Considering that my UPS appears as a battery in KDE when I plug the USB cable in, I wouldn't be surprised if it's treated the same as a laptop battery across most of the stack
- telotortium 1y agoWas the title changed since this comment? It now says “How to trigger a command on Linux when power switches from AC to battery”, which seems perfectly clear. I’m guessing “from AC to battery” was not present initially?
- nemomarx 1y agoYeah, it was when disconnected from power at first
- mrheosuper 1y ago>. Someone steals it, which involves unplugging it from the wall. At the moment it is unplugged it automatically shuts down You could achieve same thing if you unplug your battery.
- solene 1y agoThanks for reporting, I updated the title, I hope it will be clearer for new readers. For the APC, use nut :)