[ntp:questions] ntp version 4.2.7p257-o

unruh unruh at invalid.ca
Tue Feb 21 16:58:44 UTC 2012


On 2012-02-21, Terje Mathisen <"terje.mathisen at tmsw.no"> wrote:
> Michael Tatarinov wrote:
>> easier :)
>>
>> #!/bin/sh
>>
>> eval `ntpq -c 'rv 0 ss_uptime'`
>>
>> let secs=$(($ss_uptime%60))
>> let mins=$(($ss_uptime/60%60))
>> let hours=$(($ss_uptime/3600%24))
>> let days=$(($ss_uptime/86400))
>>
>> echo "${days}d ${hours}h ${mins}m ${secs}s"
>>
>
> I'm positive perl can do this in a line or two, while running on both 
> *ix and Win* platforms...
>
> I'll try with '123456' as the number of seconds of uptime:
>
> C:\>perl -e "use POSIX qw/strftime/;printf('%d %s',123456/86400, 
> strftime('%H:
> %M:%S',gmtime(123456)))"
> 1 10:17:36

Could also do it in one line in bash, at the expense of incomprehension.

echo $((12345678/(3600*24))) $((12345678/3600%24)) $((12345678/60%60)) $((12345678%60))

But what is the point.  Human readability is far more important than
space.


>
> I.e. that seems to work, but I haven't found a way for the built-in 
> strftime() to output number of days, so I had to handle that separately. :-(
>
> Terje
>



More information about the questions mailing list