[ntp:questions] ntp version 4.2.7p257-o

Terje Mathisen "terje.mathisen at tmsw.no" at ntp.org
Tue Feb 21 14:26:38 UTC 2012


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

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

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"



More information about the questions mailing list