feels like I visited stackoverflow 100 times before. Always found good solutions, but now I'm stuck.
I want to monitor how long a computer runs every day. This is part of a program written in Ruby, running on a Fedora machine.
Previously I did similar things under Windows, where it is possible to catch the related power events using WndProc. However, with Fedora (or Linux in general) I don't find a good hook to detect power-on and power-off/suspend/hibernate/....
Any suggestion is highly appreciated.
Thanks, jayrock
EDIT: Seems I haven't been clear in what I want to achieve. Actually want to have information about not only the current uptime but also past uptimes. Thus I should know "the computer has been running for x hours over the last 14 days" or similar.
Another addition is that e.g. the last
command doesn't do the job either - it doesn't show if the system goes to hibernate or suspend.
I don't know the ruby specifics but there is a command uptime in linux.
I think in ruby you need to use System
so it would be something like
system 'uptime'
Then you can parse the results of that