Skip to content

Instantly share code, notes, and snippets.

@mamu7211
Created August 17, 2017 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamu7211/c44090d6b4d862f019b089fc6cb6e84e to your computer and use it in GitHub Desktop.
Save mamu7211/c44090d6b4d862f019b089fc6cb6e84e to your computer and use it in GitHub Desktop.
Prepend Maven Output with timestamp
#!/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