Precise system uptime??

OK folks, my first post here.. hope the community can come up with a clever solution. Cross posting this in the Solaris and Shell scripting forums, as problem is scripting problem specifically on Solaris platform.

I am trying to detect a host's uptime with greater precision than is offered up by the usual suspects (e.g. uptime, who -b, last reboot -n 1, ...). These all offer only hour:minute precision, and don't include the year.

if all the target hosts were running "modern" Solaris, I might be able to grope for answer down /proc/0 (init) path for a useable timestamp, but script must run a) on older Solaris hosts, some with several hundred days of uptime, and b) without any elevated priviledges.

if I could compile some C program, I would grab the output of times(), do some math, and return a standard time value of N seconds since epoch. For the sake of this question, I must rule out that possibility. The solution must be basic Perl or shell script, executing any standard tools included with the Solaris distribution.

Anyone know of a value to inspect using kstat? mdb? dtrace?

Here is a way to get the uptime in seconds that doesn't require root privilege:

kstat -p unix:0:system_misc:boot_time|nawk '
{
  srand();
  printf("%d s\n",srand()-$2);
}'
1 Like