Last active
August 29, 2015 14:10
-
-
Save tksk/6ad661885c92922ba308 to your computer and use it in GitHub Desktop.
annotate each output lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# this script was downloaded from: | |
# http://jeroen.a-eskwadraat.nl/sw/annotate | |
# and is part of devscripts 2.10.53ubuntu3 | |
# Executes a program annotating the output linewise with time and stream | |
# Version 1.2a | |
# Copyright 2003, 2004 Jeroen van Wolffelaar <jeroen@wolffelaar.nl> | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; version 2 of the License | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software | |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
DATE_FMT=${AO_DATE_FMT:-%Y/%m/%d %H:%M:%S} | |
addtime () | |
{ | |
while IFS='' read line; do | |
echo "`date +"$DATE_FMT"` [$1] $line" | |
done | |
} | |
OUT=`mktemp /tmp/annotate.XXXXXX` || exit 1 | |
ERR=`mktemp /tmp/annotate.XXXXXX` || exit 1 | |
rm -f $OUT $ERR | |
mkfifo $OUT $ERR || exit 1 | |
addtime O < $OUT & | |
addtime E < $ERR & | |
echo "`date +"$DATE_FMT"` [I] Started $@" | |
"$@" > $OUT 2> $ERR ; EXIT=$? | |
rm -f $OUT $ERR | |
wait | |
echo "`date +"$DATE_FMT"` [I] Finished with exitcode $EXIT" | |
exit $EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment