Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would like to know the time when a linux box has booted up last year. Is there any way to ask the computer at which time it has been booted up ?

thanks.

share|improve this question

4 Answers 4

up vote 10 down vote accepted

Try uptime or last -x.

share|improve this answer
    
Thanks but this gives the actual boot time, what I'm looking for is a list of boot times. –  marc.riera Aug 16 '10 at 8:08
    
Yes, that's why I mentioned last -x. Depending on your log rotation policy you might need to provide another wtmp file e. g. last -x -f /var/log/wtmp.1. –  joschi Aug 16 '10 at 8:26
    
:) Many thanks. This was what I wanted. :) –  marc.riera Aug 17 '10 at 9:12

Last should give you the boot times, looking for the reboot or boot usernames. If need be you may need to find and use the flag that lets you load the older last logs

share|improve this answer

Perhaps ps aux | grep init gives you detailed enough information? After a long(ish) uptime it shows you the date the init process was started.

If that's not accurate enough, see /proc/stat and the btime value there. It's the Unix time in seconds when the system was last booted up. To parse it, use your favourite date manipulating tool, for example Perl Date::Manip module:

grep btime /proc/stat | cut -d ' ' -f2 | perl -MDate::Manip -lane 'printf "%s\n", UnixDate(ParseDateString("epoch $_"), "%c");'

In my test server that returns

Mon Jul 19 15:45:12 2010

Which is the last the the server was restarted.

share|improve this answer

On Linux, there's the uprecords utility that records all your uptime history. You have to install it first to start recording your uptimes though (i.e. it won't show your past uptimes).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.