Last active
August 2, 2016 11:37
-
-
Save porn/bd0d545820acdd2e7d6076c6158a4200 to your computer and use it in GitHub Desktop.
prepend timestamp and custom text before stdout and stderr
This file contains hidden or 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 | |
COMMAND=./test.sh | |
STDERR=./test.err | |
STDOUT=./test.out | |
# prepend timestamp followed by given string before each line of the output | |
IFS='' # preserve whitespaces | |
timestamp(){ while read line; do echo `date "+%Y-%m-%d %H:%M:%S"` $1 $line; done } | |
{ $COMMAND 2>&3 | timestamp "[$COMMAND]:" > $STDOUT; } \ | |
3>&1 | timestamp "[$COMMAND] ERROR:" > $STDERR & |
This file contains hidden or 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 | |
sleep 1 | |
echo "stderr sample" 1>&2 | |
sleep 1 | |
echo "stdout..." | |
echo " ...sample" | |
sleep 1 | |
echo " stderr sample 2" 1>&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment