Linux Uptime in Seconds: Difference between revisions

From Leo's Notes
This page was last edited on 1 September 2019, at 06:22.
Created page with "To get the system's uptime in seconds, you can use /proc/uptime. <syntaxhighlight lang="bash" line start="1" enclose="div"> #!/bin/sh Uptime=$(</proc/uptime) Uptime=${Uptim..."
 
m Text replacement - "Category:Linux{{Navbox Linux}}" to "{{Navbox Linux}}Category:Linux"
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
To get the system's uptime in seconds, you can use /proc/uptime.
To get the system's uptime in seconds, you can read the first value from /proc/uptime.


# cat /proc/uptime
421679.97 841913.42
The first value is the system uptime in seconds. The second value is the amount of time the system has been idle. Notice that the idle time is greater than the actual uptime. This is because the time is the sum of all the cores on the system.
To get an integer from the value above, you could do something like:


<syntaxhighlight lang="bash" line start="1" enclose="div">
<syntaxhighlight lang="bash" line start="1" enclose="div">
Line 12: Line 18:




[[Category:Linux]]
 
{{Navbox Linux}}[[Category:Linux]]

Latest revision as of 06:22, 1 September 2019

To get the system's uptime in seconds, you can read the first value from /proc/uptime.

# cat /proc/uptime
421679.97 841913.42

The first value is the system uptime in seconds. The second value is the amount of time the system has been idle. Notice that the idle time is greater than the actual uptime. This is because the time is the sum of all the cores on the system.

To get an integer from the value above, you could do something like:

#!/bin/sh

Uptime=$(</proc/uptime)
Uptime=${Uptime%%.*}

echo $Uptime