Task Check
The purpose of this document is to show an example of how to start and check a series of bash tasks.
function now() #################### # now() -> 2014-12-13T192908Z #################### { now=`date --utc --iso-8601=seconds` echo "$now" } function check_task() #################### # check_exit $? "Task description" # # Inputs: # $? - Special Bash variable indicating the success or failure # of the previous command. # "Task" - A description of what was attempted # # Outputs: # Echoes the thing tha failed and terminates the script. # #################### { now=$(now) status=${1} task=${2} if ! [ ${status} = 0 ]; then echo " - $now: FAIL: ${task}" exit 1 fi echo " - $now: PASS: ${task}" } function start_task() #################### # start_task "Task description" # # Inputs: # "Task" - A description of what was attempted # # Outputs: # A printed, timestamped string indicating the time the task was started # #################### { now=$(now) task=${1} echo echo " - $now: START: ${task}..." } now=$(now) echo echo echo "$now: <this script> starting..." task="Doing this task" start_task "${task}" #<run command here> check_task $? "${task}" echo echo "$now: Done all!"