To put some ''D'' around Michael''s suggestion try
something like:
$ pfexec dtrace -qn ''fbt:genunix:ddi_get_lbolt:return { \
lbolt = args[1]; \
lboltsec = (lbolt / 100); \
days = (lboltsec / 86400); \
hours = (lboltsec / 3600) - (days * 24); \
minutes = (lboltsec / 60) - (days * 1440) - (hours * 60); \
seconds = (lboltsec % 60); \
printf("uptime %d days, %d hours, %d minutes, %d seconds\n", days,
hours, minutes, seconds); \
exit(0); \
}''
uptime 0 days, 6 hours, 29 minutes, 38 seconds
Note if your script is doing other things besides grabbing the lbolt you
don''t want to exit(0) so look to use the profile provider or put the
calculations & printf() statement somewhere else so it doesn''t get
called at high frequencies.
If you''d rather just print the lbolt and do some post-processing you
could use the trace() functionality within D to get the lbolt value:
$ pfexec dtrace -qn ''dtrace:::BEGIN { trace(`lbolt); exit(0);
}''
2539374
If all you want to do is execute ''uptime'' from within D look
at the system() function - Note you''ll need to be in destructive/write
mode for this.
$ pfexec dtrace -wqn ''dtrace:::BEGIN { system("uptime");
exit(0); }''
4:27am up 7:07, 3 users, load average: 0.08, 0.08, 0.07
Would kstat work for you?
$ kstat -p unix:0:system_misc:lbolt
unix:0:system_misc:lbolt 2413045
--
This message posted from opensolaris.org