NUT Package change
-
Just looking for someone to help change the seconds of runtime to hours, minutes, and seconds. Anyone know how to do this?
-
You'd have to modify the status_nut.php file in /usr/local/www to take the array value $ups['battery.runtime'], convert it to hours/minutes/seconds format, then print it. I'm no PHP expert and I'm sure there are probably more elegant ways to do it but I just made the following changes:
1. Add a new function to the /* functions */ section at the top of the file that converts seconds to an array in hms format:
function secs2hms($secs) { if ($secs<0) return false; $m = (int)($secs / 60); $s = $secs % 60; $h = (int)($m / 60); $m = $m % 60; return array($h, "h ", $m, "m ", $s, "s "); }
2. Find the following line near the end of the file:
tblrow('Runtime Remaining:', $ups['battery.runtime'], ' seconds');
…and change it to the following:
tblrow('Runtime Remaining:', implode(secs2hms($ups['battery.runtime'])));
The result looks something like this:
If anyone else has a better way to do this feel free to comment.