Rootless Boot Time
So, someone asked me an interesting question today…
“I’m trying to calculate the date that my server booted using who -r...
But it doesn’t return anything!”
My colleague wanted to find out the specific time and date that his server came up. This meant that uptime was useless; it only gives the time elapsed since last boot, not the time and date of the boot itself!
A quick strace who -r shows that it’s trying to open up the /var/run/utmp file, which on our systems is locked down to be readable by root only — that’s why the command didn’t return anything for him.
Other solutions to this problem prove to have similar results (for example, last tries to open /var/log/wtmp, which we keep similarly guarded.)
To help my colleague solve his problem, a bit of creativity was required. I soon found out that the first column of the /proc/uptime file shows how long a system has been up in seconds.
Grab that number, strip off the decimal point, perform a bit of math with date and voila: