I will also talk about my results. The idea behind all these examples is to stimulate overall quality. It is also important to ensure that the end result is safe enough.
Logging
It is very important to have proper logging from the same beginning. I'm just trying to think about using products.
TAG="foo" LOG_FILE="example.log" function log() { if [ $HIDE_LOG ]; then echo -e "[$TAG] $@" >> $LOG_FILE else echo "[`date +"%Y/%m/%d:%H:%M:%S %z"`] [$TAG] $@" | tee -a $LOG_FILE fi } log "[I] service start" log "[D] debug message"
Team test
This applies to security, real life and proper error handling. May be optional.
function is_command () { log "[I] check if commad $1 exists" type "$1" &> /dev/null ; } CMD=zip if is_command ${CMD} ; then log "[I] '${CMD}' command found" else log "[E] '${CMD}' command not found" fi
Template Processing
It could only be my subjective opinion, but in any case. I used several different ways to create some / etc configuration directly from the script. Perl, sed, and others do the job, but they look a little scary.
I recently noticed a better way:
function process_template() { source $1 > $2 result=$? if [ $result -ne 0 ]; then log "[E] Error during template processing: '$1' > '$2'" fi return $result } VALUE1="tmpl-value-1" VALUE2="tmpl-value-2" VALUE3="tmpl-value-3" process_template template.tmpl template.result
Template example
echo "Line1: ${VALUE1} Line2: ${VALUE2} Line3: ${VALUE3}"
Result Example
Line1: tmpl-value-1 Line2: tmpl-value-2 Line3: tmpl-value-3
Renat Gilmanov Dec 25 2018-12-12T00: 00Z
source share