#!/bin/sh ## A time-reporting wrapper for debugging the verbose output of other programs ## Usage: timed-debug [-#] COMMAND [COMMAND_ARGS] ## -# Seconds between time reports (default=5). ## Use -0.001 for insane accuracy. Decimals requires GNU sleep. ## --real-help Get the real help. ## Example aliases (including v0.1, which was sa-timed-debug): ## alias sa-timed-debug='timed-debug -0.33 spamassassin -D' ## alias pin='timed-debug -15 ping -n' ## v0.3 (c) 2009 by Adam Katz , Apache 2.0 License. local_help() { sed -e '/^## /!d' -e s/// "`which $0 2>/dev/null || echo $0`"; } case "$1" in -[0-9]* ) time="${1#-}" ;; -.[0-9]* ) time="0${1#-}" ;; # add missing leading zero --real-help*) gethelp=true; shift; set x "$@" "--help" ;; -h*|--h* ) local_help; exit 0 ;; -* ) echo "${0##*/}: Bad argument '$1'" >&2; local_help; exit 1 ;; esac if [ "x$1" = "x-${1#-}" ]; then shift; fi if [ $# = 0 ]; then echo "${0##*/}: Missing COMMAND" >&2; local_help; exit 1; fi export PID=$$ [ -z "$gethelp" ] && ( while ps $PID >/dev/null 2>&1; do # output timing lines while program runs date +"%Y%m%d %T ---- $*" if ! sleep ${time:=5} 2>/dev/null; then time=5; sleep $time; fi # invalid->5 done )& exec "$@"