gistlib
You can use uptime command and parse the result to get the system boot time. Here's an example:
uptime
main.rbdef system_boot_time_seconds output = `uptime` uptime_parts = output.split('up ') uptime = uptime_parts[1].split(',').first.strip parts = uptime.split(':').map(&:to_i) seconds = (parts[0] * 60 * 60) + (parts[1] * 60) + parts[2] return seconds end puts system_boot_time_seconds 290 chars11 lines
def system_boot_time_seconds output = `uptime` uptime_parts = output.split('up ') uptime = uptime_parts[1].split(',').first.strip parts = uptime.split(':').map(&:to_i) seconds = (parts[0] * 60 * 60) + (parts[1] * 60) + parts[2] return seconds end puts system_boot_time_seconds
This will output the number of seconds since the system was booted.
gistlibby LogSnag