Created
April 18, 2012 06:23
-
-
Save ssbarnea/2411440 to your computer and use it in GitHub Desktop.
Bash wrapper script that calls another exec and logs it’s execution output and return code
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 | |
# install: | |
# * rename the original script to script.original | |
# * rename the wrapper.sh to script | |
# * DONE! all calls are going to be logged now | |
TIMESTAMP=`date -u +"%Y-%m-%dT%H:%M:%SZ"` | |
ME=`basename $0` | |
WRAPPED_COMMAND=$ME.original | |
echo "${TIMESTAMP} exec: $0 $@" >>${ME}.stdout.log | |
#${WRAPPED_COMMAND} "$@"|tee -a "${LOGFILE}" | |
${WRAPPED_COMMAND} "$@" > >(tee -a ${ME}.stdout.log) 2> >(tee -a ${ME}.stderr.tmp >&2) | |
RET=$? | |
TIMESTAMP_END=`date -u +"%Y-%m-%dT%H:%M:%SZ"` | |
if [ -s ${ME}.stderr.tmp ] # if we have something logged to stderr (not usual) | |
then | |
echo "${TIMESTAMP} exec: $0 $@" >>${ME}.stderr.log | |
cat >> ${ME}.stderr.log | |
echo "${TIMESTAMP_END} retured: ${RET}" >>${ME}.stderr.log | |
fi | |
rm -f "${ME}.stderr.tmp" | |
echo "${TIMESTAMP_END} retured: ${RET}" >>${ME}.stdout.log | |
exit $RET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment