Mercurial > repos > bcclaywell > microbiome_pplacer_suite
diff util.sh @ 0:d4690e65afcd draft
Uploaded
author | bcclaywell |
---|---|
date | Thu, 26 Feb 2015 18:16:36 -0500 |
parents | |
children | b6ece07bec6a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util.sh Thu Feb 26 18:16:36 2015 -0500 @@ -0,0 +1,52 @@ +#!/bin/bash + +extify() { + local REQ_EXT=$1 + shift + + local OUTPUT="" + local FILE + for FILE in $*; do + local BASENAME=$(basename ${FILE}) + local EXT=${BASENAME##*.} + if [[ ${EXT} != ${REQ_EXT} ]]; then + local LINK="${BASENAME%%.*}.${REQ_EXT}" + if [[ ! -f ${LINK} ]]; then + ln -s ${FILE} ${LINK} + fi + FILE="${LINK}" + fi + OUTPUT="${OUTPUT} ${FILE}" + done + + echo ${OUTPUT} +} + +# from http://www.linuxjournal.com/content/use-date-command-measure-elapsed-time +timer() { + if [[ $# -eq 0 ]]; then + echo $(date '+%s') + else + local stime=$1 + etime=$(date '+%s') + + if [[ -z "$stime" ]]; then stime=$etime; fi + + dt=$((etime - stime)) + ds=$((dt % 60)) + dm=$(((dt / 60) % 60)) + dh=$((dt / 3600)) + printf '%d:%02d:%02d' $dh $dm $ds + fi +} + +on_exit() { + echo "Elapsed time: $(timer ${START_TIME})" +} + +set -eux + +xargs -n 1 -0 < /proc/self/environ > env.log + +START_TIME=$(timer) +trap on_exit EXIT