Skip to content

Instantly share code, notes, and snippets.

@wa5znu
Last active March 4, 2021 22:28
Show Gist options
  • Save wa5znu/cd983d43e54412440648de1ec4d15ac4 to your computer and use it in GitHub Desktop.
Save wa5znu/cd983d43e54412440648de1ec4d15ac4 to your computer and use it in GitHub Desktop.
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
error() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
echo -e "\n\n`date -u --rfc-3339=seconds|sed -e's/\+00:00/Z/'` [ERROR] $0:${parent_lineno}:${message}; exiting with status ${code}\n\n"
else
echo -e "\n\n`date -u --rfc-3339=seconds|sed -e's/\+00:00/Z/'` [ERROR] in $BASH_SOURCE:${parent_lineno}:; exiting with status ${code}\n\n"
fi
exit "${code}"
}
trap 'error ${LINENO}' ERR
log_info() {
local message="$1"
echo "`date -u --rfc-3339=seconds|sed -e's/\+00:00/Z/'` [INFO] $0:${message}"
}
log_error() {
local message="$1"
echo "`date -u --rfc-3339=seconds|sed -e's/\+00:00/Z/'` [ERROR] $0:${message}"
}
# ... your code here ...
log_info "Cleaning Up"
${SCRIPT_DIR}/cleanup.sh
log_info "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment