Linux Uptime in Seconds: Difference between revisions
From Leo's Notes
This page was last edited on 27 May 2013, at 20:58.
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..." |
No edit summary |
||
| Line 1: | Line 1: | ||
To get the system's uptime in seconds, you can | 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 10: | Line 16: | ||
echo $Uptime | echo $Uptime | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Linux]] | [[Category:Linux]] | ||
Revision as of 20:58, 27 May 2013
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