Hi all.

I am just beginning to play with Linux, so I have some very noob-ish questions.

I am using the Cygwin console on a Windows 7 computer, connecting to a server running a Gentoo kernel. At the moment, I am exploring some of the real basic commands: cp, pwd, ls, mkdir, less, du, etc. So far, so good.

However, I would also like to determine the last time the server was shut down. This task has me puzzled.

The “w” command gives:

12:07:49 up 52 days,  2:32,  1 user,  load average: 0.06, 0.15, 0.17
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
supportM pts/0     09:47    0.00s  0.44s  0.29s sshd: supportManager_ [priv]

which seems to indicate the last reboot of the Gentoo box was 52 days ago.
'uptime' gives the same.

'ps -fp 1' gives:

UID        PID  PPID  C STIME TTY          TIME       CMD
root         1     0         0  Mar23   ?           00:00:01   init [3]

'who -b' gives the same.

'last reboot' gives

wtmp begins Wed May  9 15:23:19 2012

cat /proc/uptime gives:

4502253.15 4205946.16

On the other hand, if I read /boot/status/boot.log with the 'less' command, it gives:

Fri Jan 7 20:05:22 UTC 2000 - . Reason for previous shutdown/reboot: 10

So far, I have seen three different dates.

Shouldn’t the boot.log file confirm the last reboot as output by 'uptime' (March 26)?

And 'last reboot' gives yet another date (May 9)!?

Am I misinterpreting these values?

Which one is the correct one for the last time the Gentoo box was powered down and powered back up?

Recommended Answers

All 5 Replies

The top line of "last reboot" will show the last time you rebooted. The bottom line "wtmp" is not the last reboot time. Also, the "uptime" command will show how many dates+hours+minutes the system has been up since last reboot. If you add that to the top line of "last reboot", you should come up with the current date+time.

The line that is outputted by "last reboot" is not the time of the last reboot but the time since when the reboots have been recorded:

wtmp begins Wed May  9 15:23:19 2012

For example, if I run the command on my laptop that I'm using now, I get this:

reboot   system boot  3.0.0-19-generic Sun May 20 16:23 - 18:18  (01:55)    
reboot   system boot  3.0.0-19-generic Fri May 18 13:16 - 17:58  (04:42)    
reboot   system boot  3.0.0-19-generic Mon May 14 23:12 - 00:06  (00:54)    
reboot   system boot  3.0.0-19-generic Fri May 11 14:06 - 18:23  (04:16)    
reboot   system boot  3.0.0-19-generic Thu May 10 16:45 - 18:08  (01:22)    
reboot   system boot  3.0.0-19-generic Wed May  9 14:58 - 18:27  (03:29)    
reboot   system boot  3.0.0-19-generic Tue May  8 10:48 - 17:55  (07:07)    
reboot   system boot  3.0.0-19-generic Wed May  2 15:43 - 18:49  (03:05)    
reboot   system boot  3.0.0-17-generic Wed May  2 15:14 - 15:42  (00:28)    

wtmp begins Tue May  1 16:24:48 2012

Clearly, if there was no reboot between now and the time from which the reboot records are still kept, all the "last reboot" command will output is the last line which tells you when the recording began.

You can trust what the "w" or "uptime" or "cat /proc/uptime" give you, which are all the same, and they give you the time since the last time the computer started (e.g. the "up-time").

As for the boot.log, this is likely only recording exceptional boot-related occurrences. For instance, on my computer, there is no such log because it probably never booted with an error / warning to report during the initial boot phase.

Member Avatar for lrirwin

This is what I use to present uptime - I call it "bootdate":
TMP=cat /proc/uptime | cut -f1 -d" " | cut -f1 -d"."
date --date="-${TMP} seconds"
But the only way to know the last shutdown time is to find the string in /var/log/syslog* or /var/log/messages* - if you still have them...
logrotate may have purged it if you aren't searching and extracting it on your own...
On a recent RedHat system, the way to find it would be:
grep " init: Disconn" messa* | sort | tail -n 1

Use Uptime command to check the uptime of the server

Use

last reboot | less

to check the last reboot time

Thanks for the help everybody.

Uptime is apparently the command I want.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.