Created
April 12, 2016 18:42
-
-
Save hvmonteiro/20fb0dc3fb1c38e28842d4e25bae83fe to your computer and use it in GitHub Desktop.
Bash Scripts
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 | |
DEBUG_FILE="debug.log" | |
LOG_FILE="info.log" | |
FAILURE=1 | |
SUCCESS=0 | |
# Outputs a message to the console | |
_print_msg () { | |
prefix=$1 | |
shift | |
msg="$@" | |
caller_script=$( basename "$(caller 1 | awk '{ print $3 }' )") | |
printf "$(date) %-7s %-10s : $msg \n" "[$prefix]" "$caller_script" | |
} | |
# Outputs a message to the console and logs it to the log file | |
_print_log () { | |
_print_msg INFO "$@" | |
_print_msg INFO "$@" >> $LOG_FILE | |
} | |
# Outputs a message to the console and logs it to the debug file | |
_print_debug () { | |
caller_function=$(caller 1 | awk '{ print $2 }') | |
_print_msg DEBUG "$caller_function() : $@" | |
-print_msg DEBUG "$caller_function() : $@" >> $DEBUG_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 | |
[ ! -f "debug.lib" ] && exit 2 | |
. debug.lib | |
_print_msg "test1" "some message here" | |
_print_log "test2" "some log message here" | |
_print_debug "test3" "some debug message here" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment