Skip to content

Instantly share code, notes, and snippets.

@dmotylev
Created December 11, 2014 16:15
Show Gist options
  • Save dmotylev/b65f64e61bb2695f0bf2 to your computer and use it in GitHub Desktop.
Save dmotylev/b65f64e61bb2695f0bf2 to your computer and use it in GitHub Desktop.
shell snippet
#!/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