Q: Scripting UPS status
I'm looking to update some of the bulky and convoluted scripts I wrote to monitor my UPS and report on events. The existing scripts use frequent execution to poll status, temporary files to communicate several valuables between one another, etc. With a fresh new battery just installed, and some time on my hands, I'm now looking to update the situation.
Here is what I am looking for ...
- A command-line tool that can tell me what the current power source is
- A command-line tool which can tell me the configured values to trigger shutdown
- A command-line tool that can tell me the status of the UPS: charge level, minutes left at current load, etc.
- A way of knowing when there is a change in power source, that does not require polling
Now, apcupsd provides all of the above. However, I found it to be an unreliable piece of software that was prone to crashing. After a few weeks of trying to understand and predict what triggered crashes, I gave up and removed it from my system.
There is a tool pmset which can help me with 1-3 above. I have no idea how resource-intensive it would be for me to run this and process the output it provides, but given that it ships with OS X I guess it is the best I can get. Are there better alternatives?
The most interesting for me is to be notified when power goes down. This is where apcupsd shined, as it triggers customisable scripts upon a power event. Unfortunately, well, see above. So the only option I have right now is to keep running commands like pmset -g | grep \* | awk '{ print $1 }' every 10 or 30 seconds to get an idea of what the current power source is, and triggering an alert if that was different from the previous run of the script. Not a very elegant solution. Hoping somebody has a better alternative!
Much appreciate any feedback.
Mac mini, Mac OS X (10.7), 1.83GHz Core2Duo, 3GB RAM, 80GB HDD
Posted on Apr 21, 2016 8:21 AM