Created
October 8, 2014 22:01
-
-
Save caiobegotti/e3c815acb2eef34a2d82 to your computer and use it in GitHub Desktop.
Log trapper, useful when you want to log all commands with a timestamp for further analysis (e.g. if your script echoes to a log file)
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 | |
function logtrap() { | |
local last="${BASH_COMMAND}" | |
local exitcode=${?} | |
# any format is ok but this will be printed BEFORE all commands, not after | |
echo "TRAPLOG: [$(date +%T)] [${exitcode}] [${last}]" | |
} | |
trap logtrap DEBUG | |
echo "testing" | |
false 12345 | |
true 09876 | |
ls -l /tmp | head | |
uname -a | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment