Linux Uptime in Seconds: Difference between revisions
From Leo's Notes
This page was last edited on 1 September 2019, at 06:22.
mNo edit summary |
m Text replacement - "Category:Linux{{Navbox Linux}}" to "{{Navbox Linux}}Category:Linux" |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 19: | Line 19: | ||
[[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