For example, in the below script startover
starts back from the top:
##########################################################################
## CHECK TIME
##########################################################################
time=$(date +%k%M)
if [[ "$time" -ge 1800 ]] && [[ "$time" -le 2200 ]];then
echo "Not a good time to transcode video!" && exit 0
else
echo "Excellent time to transcode video!" && echo "Lets get started!"
fi
##########################################################################
## CHECK TIME
##########################################################################
startover
Also keeping in mind exit 0
should be able to stop the script.
You could "recurse" using the following line:
Since
$0
is the path to the current script, this line starts the script without creating a new process, meaning you don't need to worry about too many restarts overflowing the process table on your machine.How about enclosing the entire script in a
while
loop? For example,You may want to add a condition to break out of the loop.
Put it in a while loop. I'd also suggest you add a "sleep" so that you're not racing your machine's CPU as fast as it will go:
This is not good practice, but what you asked for.
Put this at the end of your script.
"$( cd "$( dirname "$0" )" && pwd )/$(basename $0)"
DO NOT USE WHILE LOOP at the start of the script since the condition below will exit the script and break the loop.
You can try trapping the exit signal so that when the script exits it restarts
Note: I add a sleep of 1 second because this will give you the time to see message. trap the exit signal and re-running the script is acting like a while loop. I am also assuming that these codes are in a script.