Created
August 17, 2017 14:55
-
-
Save mamu7211/c44090d6b4d862f019b089fc6cb6e84e to your computer and use it in GitHub Desktop.
Prepend Maven Output with timestamp
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 | |
# | |
# Prepends a date string in front of the Maven output. | |
# A workaround for http://jira.codehaus.org/browse/MNG-519 "Timestamps on messages" | |
[ -z "${AWK}" ] && AWK="$(which gawk 2>/dev/null)" || AWK="$(which awk 2>/dev/null)" || { echo "Error: Could not find AWK tool."; exit 1; } | |
"${AWK}" 'BEGIN { print strftime("%Y-%m-%d %H:%M:%S"); }' 2>&1 > /dev/null || { echo "Error: your AWK version does not support strftime() function." && exit 1; } | |
mvn "${@}" 2>&1 |"${AWK}" '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' | |
# see comp.unix.shell FAQ: (http://cfajohnson.com/shell/cus-faq-2.html) | |
# "How do I get the exit code of cmd1 in cmd1|cmd2" | |
exit ${PIPESTATUS[0]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment