Skip to content

Instantly share code, notes, and snippets.

@thomd
Forked from mahemoff/log.sh
Created June 28, 2013 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomd/5888876 to your computer and use it in GitHub Desktop.
Save thomd/5888876 to your computer and use it in GitHub Desktop.
#!/bin/bash
##########################################################################
# library
##########################################################################
# via http://stackoverflow.com/a/12199798/18706
function format_date {
((h=${1}/3600))
((m=(${1}%3600)/60))
((s=${1}%60))
printf "%02d:%02d:%02d\n" $h $m $s
}
start=$(date +"%s")
function age {
now=$(date +"%s")
the_age=$(($now-$start))
format_date $the_age
}
function announce {
echo `age`" ${FUNCNAME[ 1 ]} $1"
}
##########################################################################
# example
##########################################################################
function setup {
announce
sleep 5
}
function finish {
announce
}
# this will output
# 00:00:00 setup
# 00:00:05 finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment