Created
December 11, 2014 16:15
-
-
Save dmotylev/b65f64e61bb2695f0bf2 to your computer and use it in GitHub Desktop.
shell snippet
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 | |
set -o nounset | |
set -o privileged | |
set -o errtrace | |
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin | |
readonly LOG_TS_FMT='+%Y-%m-%d %H:%M:%S' | |
function logTimestamp { | |
date $LOG_TS_FMT | |
} | |
function error { | |
echo "E: $(logTimestamp) $@" >&2 | |
} | |
function warn { | |
echo "W: $(logTimestamp) $@" >&2 | |
} | |
function info { | |
echo "I: $(logTimestamp) $@" >&2 | |
} | |
function errHandler { | |
local SRC=$1; shift | |
local LINE=$1; shift | |
local CMD=$1; shift | |
error "failed execution of '$CMD' at $(basename $SRC):$LINE" | |
exit 255 | |
} | |
function cleanup { | |
return 0 | |
} | |
trap 'errHandler $BASH_SOURCE $LINENO $BASH_COMMAND' ERR | |
trap 'cleanup; exit 1' TERM | |
trap 'cleanup; trap - INT; kill -INT $$; exit 1' INT | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment