0

I can get uptime from uptime but what about time between boot and shutdown historically?

If the last part was the duration (days+hour:minutes), it doesn't make sense that time between reboot is overlapped

uptime
 04:32:34 up 7 days,  1:45,  6 users,  load average: 0.72, 1.80, 2.43
last -F | grep -i boot
reboot   system boot  6.0.12-76060006- Wed Feb 15 10:49:34 2023 - Thu Feb 16 23:37:21 2023 (1+12:47)
reboot   system boot  6.0.12-76060006- Tue Feb 14 18:25:20 2023 - Thu Feb 16 23:37:21 2023 (2+05:12)
reboot   system boot  6.0.12-76060006- Tue Feb 14 14:13:15 2023 - Tue Feb 14 18:24:37 2023  (04:11)
reboot   system boot  6.0.12-76060006- Sun Feb 12 18:04:08 2023 - Tue Feb 14 14:03:15 2023 (1+19:59)
reboot   system boot  6.0.12-76060006- Sun Feb 12 17:45:53 2023 - Tue Feb 14 14:03:15 2023 (1+20:17)
reboot   system boot  6.0.12-76060006- Fri Feb 10 21:43:35 2023 - Sun Feb 12 17:41:39 2023 (1+19:58)
reboot   system boot  6.0.12-76060006- Thu Feb  9 02:40:16 2023 - Fri Feb 10 21:42:55 2023 (1+19:02)
reboot   system boot  6.0.12-76060006- Thu Feb  9 01:15:53 2023 - Fri Feb 10 21:42:55 2023 (1+20:27)
reboot   system boot  6.0.12-76060006- Tue Feb  7 13:13:54 2023 - Fri Feb 10 21:42:55 2023 (3+08:29)
reboot   system boot  6.0.12-76060006- Tue Feb  7 13:11:14 2023 - Fri Feb 10 21:42:55 2023 (3+08:31)
reboot   system boot  6.0.12-76060006- Mon Feb  6 17:45:21 2023 - Fri Feb 10 21:42:55 2023 (4+03:57)
reboot   system boot  6.0.12-76060006- Sat Jan 28 23:29:20 2023 - Fri Feb 10 21:42:55 2023 (12+22:13)
reboot   system boot  6.0.12-76060006- Sat Jan 28 17:18:26 2023 - Fri Feb 10 21:42:55 2023 (13+04:24)
reboot   system boot  6.0.12-76060006- Sun Jan 22 17:03:11 2023 - Fri Feb 10 21:42:55 2023 (19+04:39)
reboot   system boot  6.0.12-76060006- Fri Jan 20 17:21:38 2023 - Sun Jan 22 17:02:27 2023 (1+23:40)
reboot   system boot  6.0.12-76060006- Fri Jan 20 17:17:16 2023 - Fri Jan 20 17:20:58 2023  (00:03)
reboot   system boot  6.0.12-76060006- Fri Jan 20 17:00:34 2023 - Fri Jan 20 17:20:58 2023  (00:20)
reboot   system boot  6.0.12-76060006- Thu Jan 19 22:21:51 2023 - Fri Jan 20 16:46:30 2023  (18:24)
reboot   system boot  6.0.12-76060006- Wed Jan 18 19:25:31 2023 - Thu Jan 19 22:21:08 2023 (1+02:55)
reboot   system boot  6.0.12-76060006- Tue Jan 17 21:59:16 2023 - Thu Jan 19 22:21:08 2023 (2+00:21)
reboot   system boot  6.0.12-76060006- Mon Jan 16 14:44:11 2023 - Tue Jan 17 21:58:23 2023 (1+07:14)
reboot   system boot  6.0.12-76060006- Fri Jan 13 16:01:13 2023 - Mon Jan 16 14:43:28 2023 (2+22:42)
reboot   system boot  6.0.12-76060006- Mon Jan  2 01:11:15 2023 - Fri Jan 13 16:00:26 2023 (11+14:49)
Kokizzu
  • 499

1 Answers1

0

Here's a little bash snippet that you can use to show the number of seconds that journalctl reports as first and last recorded log message. It's not strictly the same as uptime, but it does give you a fairly consistent impression. It simply parses the reported dates as UNIX timestamps and shows the difference, thus in seconds.

journalctl --list-boots | \
  awk 'NR > 1 {print $4"T"$5" "$8"T"$9}' | \
  while read t1 t2; do \
     echo $(( "$(date +"%s" -s "$t2")" - "$(date +"%s" -s "$t1")" )); 
  done;