#!/bin/bash LOGFILE="$0.log" # create a log file based on the executable's name echo "$(date +'%x %X'): STARTING" >> "${LOGFILE}" # Log the start of the run if [ $(grep "COMPLETE" "${LOGFILE}" | wc -l) -lt 1 ] # check if it has already been run... then echo "Hello World! The time is $(date +'%x %X') and I'm running on host: ${HOSTNAME}. I'm running task $1 :-)" sleep 1 if [ $(( ( RANDOM % 10 ) + 1 )) -gt 4 ] # will run successfully something like 60% of the time then echo "SUCCESS!" echo "$(date +'%x %X'):COMPLETE" >> "${LOGFILE}" else echo "Failure" # Oh boo. This will not be logged fi else echo "$(date +'%x %X'): NOT REPEATING" >> "${LOGFILE}" # Log that run has already been performed fi