Coding style used for my bash projects (v2.6 Nov 2016)
Coding style used for my bash projects (v3.0 Dec 2016)
++++++ Header
@ -143,7 +143,10 @@ The following log levels exist:
- CRITICAL: Program execution is halted
Can be called with:
Logger "My message" "LOGLEVEL"
Logger "My message" "LOGLEVEL" $retval
$retval is an optional parameter that passes the exit code of the command that triggered the logging message
$retval, along with function stack, script pid and current pid can be found in the ERROR /WARN alert files ($RUN_DIR/$PROGRAM.Logger.error.$SCRIPT_PID)
++++++ Eval
@ -153,14 +156,36 @@ The basic way of doing is:
cmd='"something '$somevar'" > some_file 2>&1'
eval $cmd &
WaitForTaskCompletion $! 0 0 $FUNCNAME
retval=$?
if [ $retval -ne 0 ]; then
Logger "Some error message" "ERROR" $retval
fi
Remote commands should always invoke bash (using '"'"' to escape single quotes of 'bash -c "command"'). It is preferable to use ssh heredoc in order to use plain code.
If local and remote code is identical, wrap remote code in a function so only minor modifications are needed.