Linux Uptime in Seconds: Difference between revisions
From Leo's Notes
This page was last edited on 29 March 2015, at 06:08.
No edit summary |
mNo edit summary |
||
| Line 20: | Line 20: | ||
[[Category:Linux]] | [[Category:Linux]] | ||
{{Navbox Linux}} | |||
Revision as of 06:08, 29 March 2015
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