我需要与Linux的“cat / proc / uptime”完全相同的输出。
例如,使用/ proc / uptime,你就可以得到
1884371.64 38646169.12
但是对于任何Mac替代品,比如“正常运行时间”,你会得到
20:25 up 20:26,6位用户,平均负载:3.19 2.82 2.76
我需要它与cat / proc /正常运行时间完全相同,但在Mac OS X上。
得到它了...
$sysctl -n kern.boottime | cut -c14-18
87988
然后我把它转换成可读格式(不记得怎么样):
1天00:26:28
Macintosh上没有“/ proc”目录。
On MacOS, you can do a command like:
sysctl kern.boottime
你会得到一个像:
kern.boottime: { sec = 1362633455, usec = 0 } Wed Mar 6 21:17:35 2013
boottime=`sysctl -n kern.boottime | awk '{print $4}' | sed 's/,//g'`
unixtime=`date +%s`
timeAgo=$(($unixtime - $boottime))
uptime=`awk -v time=$timeAgo 'BEGIN { seconds = time % 60; minutes = int(time / 60 % 60); hours = int(time / 60 / 60 % 24); days = int(time / 60 / 60 / 24); printf("%.0f days, %.0f hours, %.0f minutes, %.0f seconds", days, hours, minutes, seconds); exit }'`
echo $uptime
将返回类似1天,20小时,10分钟,55秒的内容