Hi All,
I am trying to get a loop bash script up and running .... I am trying to get a search loop up and running ... once its finds the latest file, it commands one section of the script, if not, it sleeps for a while and then searches again ...
Once the loops are finished - it reports such and (may) action other tasks.
Code:
echo "Starting loop until File ($file) found ..."
for i in {1..10}; do
if wget -N $url/$file | grep 304; then
echo "File $file found ..."
if [ $get_file == "yes" ]; then
echo "Time to Download the Latest File -> $file"
fi
#
if [ $home_backup == "yes" ]; then
echo "Making Home Backup on NAS Server [ XXX Folder ]"
home_backup
fi
echo "Breaking Loop .... Job Complete"
break
else
echo "($file) NOT modified on server. Omitting download"
echo "Sleeping for $sleep until trying again...zzZZzz"
sleep $sleep
fi
# Fall back if nothing found or task not completed...
# Should not really end up here...
#echo " Loops Completed - Nothing Found or Task not Completed - Try again"
done
I am trying to figure out who to exit the script so that the "Fallback" section of the script only runs when the loops have finished and either of the other "IF" have not been successful.
I am trying to implement an ELIF but having a problem to get it to work as such based on the initial IF task. I am thinking the problem is in the last part of the script, and placement of the IF,THEN,ELSE etc etc...
Is there a way to exit out of the entire script - say after the "BREAK" if reached?
Anyone know a way around this to tidy it up and not run specific sections of the script unless triggered....
Thanks a million!