Created
July 25, 2013 02:26
-
-
Save sevaine/6076428 to your computer and use it in GitHub Desktop.
Stock Bash script with logging / exit function and script name / location enumeration
This file contains hidden or 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 | |
log() { | |
local TIMESTAMP="[$(date)]" | |
if $(echo "${1}" | grep ^WARNING 2>&1 >/dev/null); then | |
echo "${TIMESTAMP}: $*" 1>&2 | |
elif $(echo "${1}" | grep ^FATAL 2<&1 >/dev/null); then | |
echo "${TIMESTAMP}: $*" 1>&2 | |
exit 1 | |
else | |
echo "${TIMESTAMP}: $*" | |
fi | |
} | |
SCRIPT="${BASH_SOURCE[0]}" | |
SCRIPT_DIR="$(cd $(dirname ${SCRIPT}) && pwd)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment