How do I determine the uptime on a SunOS UNIX box in seconds only?
On Linux, I could simply cat /proc/uptime & take the first argument:
cat /proc/uptime | awk '{print $1}'
I'm trying to do the same on a SunOS UNIX box, but there is no /proc/uptime. There is an uptime command which presents the following output:
$ uptime
12:13pm up 227 day(s), 15:14, 1 user, load average: 0.05, 0.05, 0.05
I don't really want to have to write code to convert the date into seconds only & I'm sure someone must have had this requirement before but I have been unable to find anything on the internet.
Can anyone tell me how to get the uptime in just seconds?
TIA
Use truss on the date command to get epoch time and subtract boot time obtained from kstat.
Thanks to Andre for a solution that will provide seconds. If anyone is looking for an answer without compiling, this script can be used. Note, as the "uptime" command does not provide seconds the solution is anything from 0 to 59 seconds out when it is run:
Hope that's of use to someone :-)
Here is a shell script that provides second resolution. Note that you need to be root for it to work.
This is a mix of some answers already given. Outputs uptime in seconds with only two commands. Tested on Solaris 9 and 10.
Use truss to extract the creation time of the directory /proc/0. (Must be run as root.)
A rather unorthodox method might be this (helped me out since the kstat yielded some weired results that did not pass cron:
Hope it helps you out - Nice side effect: You have the time bits available for calculations.