1

I would like to see the start/stop times of a Linux PC.

I found this command, but the output is wrong:

last reboot -F
reboot   system boot  4.15.0-46-generi Thu Mar 14 10:04:27 2019 - Thu Mar 14 15:31:11 2019  (05:26)

That's not true. Instead of 10:04 it is 09:04.

See related question: https://askubuntu.com/questions/854567/last-reboot-is-missing-one-hour/859782

How can I see the correct start/stop times on Ubuntu 18.04?

guettli
  • 3,113
  • 14
  • 59
  • 110
  • Any chance the reboot was during Daylight saving time and clock was adjusted one hour? – Dextro67 Mar 15 '19 at 09:31
  • @Dextro67 I did not change the clock by hand, and the wrong output of the `reboot` commands happens every day. I don't care for the internals, I just want reliable numbers. – guettli Mar 15 '19 at 09:40
  • Then set the system time zone to UTC. – Michael Hampton Mar 18 '19 at 17:08
  • @MichaelHampton I need to change the system time zone, just to be able to get the start/stop times reliably? OK, this was new to me. – guettli Mar 19 '19 at 07:51
  • @guettli Please, **do not cross post**. [You've already asked the same question ~2 years ago](https://askubuntu.com/questions/854567/last-reboot-is-missing-one-hour/859782). – Paradox Mar 20 '19 at 16:31
  • What timezone set on this box? – Alexander Tolkachev Mar 21 '19 at 13:45
  • @AlexanderTolkachev does this matter? I want a solution which works with any time zone. AFAIK it is CET. – guettli Mar 21 '19 at 14:32
  • Why do you need this information? – ewwhite Mar 23 '19 at 11:11
  • @ewwhite the start/stop times get logged by a custom tool at my job (attendance clock) If the custom tool fails, then you need to adjust the values by hand. I want simple way to get these values if the custom tool fails. – guettli Mar 25 '19 at 13:47
  • I don't know if the start and stop times of a PC is a good and deterministic way of acquiring this information, but the answer below seems to provide what you need. – ewwhite Mar 25 '19 at 13:53
  • @ewwhite I agree, start/stop times are not a good solution for this. But that's the way it is. This is not part of the question. I just want a solution for the current situation. And I am happy, since I found a solution. There are more important things for me than "start/stop times are not a good solution for this". – guettli Mar 25 '19 at 14:03

2 Answers2

8
# timestamps corresponds to your current timezone
user@node:~$ journalctl --list-boots
-3 0f2fcb9569384a2aa2d5492505f86cda Tue 2018-11-27 16:45:22 CET—Thu 2018-11-29 10:10:07 CET
-2 646787bd244d4230a5986f00207c1e8c Sun 2019-02-24 19:50:23 CET—Tue 2019-02-26 22:49:29 CET
-1 c922041a9a3847babd51ac79dd06923c Wed 2019-02-27 08:27:28 CET—Sun 2019-03-03 08:52:52 CET
 0 0aa03fbca4bf4976b922f9f77c63f65a Sun 2019-03-03 09:02:47 CET—Mon 2019-03-18 17:10:08 CET

# timestamps corresponds to universal timezone
user@node:~$ journalctl --list-boots --utc
-3 0f2fcb9569384a2aa2d5492505f86cda Tue 2018-11-27 15:45:22 UTC—Thu 2018-11-29 09:10:07 UTC
-2 646787bd244d4230a5986f00207c1e8c Sun 2019-02-24 18:50:23 UTC—Tue 2019-02-26 21:49:29 UTC
-1 c922041a9a3847babd51ac79dd06923c Wed 2019-02-27 07:27:28 UTC—Sun 2019-03-03 07:52:52 UTC
 0 0aa03fbca4bf4976b922f9f77c63f65a Sun 2019-03-03 08:02:47 UTC—Mon 2019-03-18 16:10:08 UTC

UTC timezone is universal that's why it is useful to avoid any daylight saving time misunderstanding issues.

From journalctl man page :

       --list-boots
           Show a tabular list of boot numbers (relative to the current boot), their IDs, and the timestamps of the first and last message pertaining to the boot.

PS : in case you have only one line returned by journalctl, just create folder /var/log/journal to enable multiple on-disk journal retention

Chaoxiang N
  • 1,218
  • 4
  • 10
  • Nice! Works, I get the correct time: "Mon 2019-03-18 08:38:11 CET—Mon 2019-03-18 17:01:44 CET" and `last reboot` is still wrong by one hour: " 09:38 - 17:01" – guettli Mar 19 '19 at 07:57
0

Grepping rsyslog stsrt/stops from /var/log/messages would likely suit your needs as that’s one of the first things to start and last things to stop on shutdown.