Junk

Junk Commit Details

Date:2014-12-14 23:54:14 (4 years 11 months ago)
Author:Nicola Fontana
Branch:master
Commit:5f1eac158a192990cf64903faf2cf5caa53e3073
Parents: ec962ecfdc7e920f1a4d78088d2496309231df16
Message:annotate-output: import from Debian devscripts

Changes:
Amisc/annotate-output (full)

File differences

misc/annotate-output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#
# This script was imported from Debian sid devscripts:
#
# https://packages.debian.org/sid/devscripts
#
# Executes a program annotating the output linewise with timestamp
# and file descriptor (stdout or stderr).
progname=$(basename $0)
addtime ()
{
while IFS= read -r line; do
echo "`date ${FMT}` $1: $line"
done
if [ ! -z "$line" ]; then
echo -n "`date ${FMT}` $1: $line"
fi
}
usage ()
{
echo \
"Usage: $progname [options] program [args ...]
Run program and annotate STDOUT/STDERR with a timestamp.
Options:
+FORMAT - Controls the timestamp format as per date(1)
-h, --help - Show this message"
}
FMT="+%H:%M:%S"
while [ "$1" ]; do
case "$1" in
+*)
FMT="$1"
shift
;;
-h|-help|--help)
usage
exit 0
;;
*)
break
;;
esac
done
if [ $# -lt 1 ]; then
usage
exit 1
fi
cleanup() { __st=$?; rm -rf "$tmp"; exit $__st; }
trap cleanup 0
trap 'exit $?' 1 2 13 15
tmp=$(mktemp -d --tmpdir annotate.XXXXXX) || exit 1
OUT=$tmp/out
ERR=$tmp/err
mkfifo $OUT $ERR || exit 1
addtime O < $OUT &
addtime E < $ERR &
echo "`date ${FMT}` I: Started $@"
"$@" > $OUT 2> $ERR ; EXIT=$?
rm -f $OUT $ERR
wait
echo "`date ${FMT}` I: Finished with exitcode $EXIT"
exit $EXIT

Archive Download the corresponding diff file

Branches