0

I wanted to get the system downtime duration i.e. system went down (could be due to a reboot or shutdown) and System came up. I tried checking few commands mentioned below.

I converted (1+06:28) to seconds thinking is the duration between when the system went down and came up. But I check further and figured that it implies days, hours and minutes. But my system did not reboot for a day or was even shutdown for a day.

Why is it showing this?

last -x | grep reboot & last -x | grep shutdown

reboot   system boot  5.14.0-325.el9.x Tue Mar  5 08:16   still running
reboot   system boot  5.14.0-325.el9.x Mon Mar  4 01:47 - 08:16 (1+06:28)
shutdown system down  5.14.0-325.el9.x Tue Mar  5 08:16 - 08:16  (00:00)


[root@ansible ~]# last reboot
reboot   system boot  5.14.0-419.el9.x Tue Mar  5 18:44   still running
reboot   system boot  5.14.0-391.el9.x Thu Feb 22 20:21 - 18:44 (11+22:23)
reboot   system boot  5.14.0-391.el9.x Mon Dec 18 14:30 - 14:46  (00:16)
reboot   system boot  5.14.0-373.el9.x Mon Dec 18 13:58 - 14:29  (00:30)
reboot   system boot  5.14.0-373.el9.x Tue Oct 10 14:42 - 14:46  (00:04)
reboot   system boot  5.14.0-368.el9.x Tue Oct 10 13:44 - 14:41  (00:57)
reboot   system boot  5.14.0-368.el9.x Wed Oct  4 19:59 - 14:41 (5+18:42)
reboot   system boot  5.14.0-368.el9.x Wed Oct  4 18:02 - 14:41 (5+20:39)
reboot   system boot  5.14.0-368.el9.x Mon Oct  2 17:29 - 18:55  (01:26)
reboot   system boot  5.14.0-366.el9.x Mon Oct  2 17:22 - 17:29  (00:06)
reboot   system boot  5.14.0-366.el9.x Thu Sep 21 17:20 - 17:21  (00:00)
reboot   system boot  5.14.0-354.el9.x Thu Sep 21 16:53 - 17:19  (00:25)
reboot   system boot  5.14.0-354.el9.x Mon Sep 18 12:17 - 13:12  (00:54)
reboot   system boot  5.14.0-354.el9.x Tue Sep  5 17:14 - 13:12 (12+19:57)
reboot   system boot  5.14.0-354.el9.x Mon Sep  4 15:21 - 13:12 (13+21:50)
reboot   system boot  5.14.0-354.el9.x Mon Sep  4 15:14 - 15:15  (00:01)
reboot   system boot  5.14.0-354.el9.x Wed Aug 30 18:03 - 15:15 (4+21:11)
reboot   system boot  5.14.0-354.el9.x Tue Aug 29 10:48 - 15:15 (6+04:26)
reboot   system boot  5.14.0-354.el9.x Mon Aug 28 20:19 - 15:15 (6+18:55)
reboot   system boot  5.14.0-354.el9.x Mon Aug 28 18:43 - 20:17  (01:33)
reboot   system boot  5.14.0-354.el9.x Mon Aug 28 18:38 - 18:43  (00:04)
reboot   system boot  5.14.0-354.el9.x Mon Aug 28 18:29 - 18:38  (00:08)



3
  • 1
    "(1+06:28)" is the time the system was up for, not the time it was down for. The downtime has to be calculated from the gap between going down at 08:16 and coming up at 08:16 - which is "less than a minute" but not more detail available.
    – pjc50
    Commented Mar 5 at 15:22
  • I have added output from the other system in my question.
    – AshKash
    Commented Mar 5 at 15:42
  • Is there a command that could show the system down duration?
    – AshKash
    Commented Mar 5 at 15:59

1 Answer 1

0

I am using Ubuntu, I believe the below entries in the journal are via the kernal so should be standard across versions.

The below command will give you your shutdowns

journalctl -a | grep "Shutting down\."

and the below command will give you startups

journalctl -a | grep "Command line:"

I am assuming you are running a linux that is using journal, you may need to slightly tweak what you are greping for to get the correct format for your linux.

journalctl -b 

gives you the journal starting from the last boot, so use that as your time reference and find the unique lines.

If you want to go a little more tricky:

journalctl -a | awk '/Command line:/{print $1" "$2" "$3" - Startup"}/Shutting down\./{ print $1" "$2" "$3" - Shutdown"}'

My journal goes back 6 months and was able to get the times for my shutdown and start ups.

If you dont want to go back so far you can add to your journalctl command -n

Otherwise you will get the dates from the entire journal.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .