Search code examples
linux

Linux uptime history


How can I get a history of uptime for my Debian box? After a reboot, I don't see an option for the uptime command to print a history of uptime. If it matters, I would like to use this uptime data for graphing a page in PHP to show my web servers uptime lengths between boots.

I'm not sure if it is based on a length of time or if last gets reset on reboot, but I only get the most recent boot timestamp with the last command. last -x also does not return any further info. It sounds like a script is my best bet.

Update: Uptimed is the information I am looking for, but I'm not sure how to grep that info in code. Managing my own script for a db sounds like the best fit for an application.


Solution

  • You could create a simple script which runs uptime and dumps it to a file.

    uptime >> uptime.log
    

    Then set up a cron job for it.