Skip to content

Instantly share code, notes, and snippets.

@mrc
Created April 30, 2013 07:34
Show Gist options
  • Save mrc/5487168 to your computer and use it in GitHub Desktop.
Save mrc/5487168 to your computer and use it in GitHub Desktop.
Poor uptime for zsh and Windows
zmodload zsh/datetime
function uptime() {
reboot_time=$(net statistics server | awk '/Statistics since/{print $3, $4, $5}')
strftime -r -s reboot_secs '%d/%m/%Y %H:%M:%S %p' "$reboot_time"
(( uptime = $EPOCHSECONDS - $reboot_secs ))
(( up_days = uptime / 86400 ))
(( up_hours = (uptime % 86400) / 3600 ))
(( up_minutes = ((uptime % 86400) % 3600 ) / 60))
(( up_seconds = ((uptime % 86400) % 3600 ) % 60))
strftime -s now_time '%H:%M:%S' $EPOCHSECONDS
printf " $now_time up %d days, %2d:%02d\n" $up_days $up_hours $up_minutes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment