spanish version - all english posts
The most common way to find out when was the last start is using the command "uptime":
root@blogspot:~# uptime 22:28:20 up 22 days, 12:48, 1 user, load average: 0.11, 0.04, 0.00
However that command doesn't tell us WHEN but HOW LONG!
Hence, only for curiosity, here are a few recipes to get that WHEN:
With "who":
root@blogspot:~# who -b system boot 2010-01-04 09:39
Using "last":
root@blogspot:~# last reboot reboot system boot 2.6.24-24-server Mon Jan 4 09:39 - 22:30 (22+12:51) wtmp begins Mon Jan 4 09:34:08 2010
Unfortunately "last" depends on the "wtmp" registry which is regularily cleaned (depending on the distribution and how is logrotate configured). For this reason in servers with a high uptime the command "last reboot" is not quite useful.
Finally, the method I like best: Using the epoch timestamp from /proc/stat:
root@blogspot:~# date -d @$(sed -n 's/btime \(\d*\)/\1/p' /proc/stat) Mon Jan 4 09:39:24 CET 2010
As usually, when I use sed, awk or grep I like to get their equivalents of each of them. So here are some alternatives of the above command (there are dozens of them):
With awk:
root@blogspot:~# date -d @$(awk '$1 ~ /btime/ {print $2}' /proc/stat) Mon Jan 4 09:39:24 CET 2010
And with grep; in this case using it's perl regexp expressions compatibility:
root@blogspot:~# date -d @$(grep -Po '(?<=btime )(\d*)' /proc/stat) Mon Jan 4 09:39:24 CET 2010
0 comments:
Post a Comment