Skip to content

Instantly share code, notes, and snippets.

@ganglio
Created July 3, 2012 19:23
Show Gist options
  • Save ganglio/3042169 to your computer and use it in GitHub Desktop.
Save ganglio/3042169 to your computer and use it in GitHub Desktop.
BASH: Revised Uptime Geeklet
#!/bin/bash
then=$(sysctl kern.boottime | awk '{print $5}' | sed "s/,//")
now=$(date +%s)
diff=$(($now-$then))
days=$(($diff/86400));
diff=$(($diff-($days*86400)))
hours=$(($diff/3600))
diff=$(($diff-($hours*3600)))
minutes=$(($diff/60))
seconds=$(($diff-($minutes*60)))
printf "Uptime: %dd%02dh%02dm%02ds" $days $hours $minutes $seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment