I am trying to write a script that will only continue executing my script if a file exits. I know the directory of the file, so its just a matter of seeing if the file exists yet. If the file has not yet been created, I want the script to wait 10 minutes (600 seconds) and try again. I was thinking of using the "until" command somehow, but can't figure it out. Please help!
required_files='/path/to/file1 /path/to/file2 /path/to/file3'
interval=600
for file in ${required_files}
do
until [[ -a "${file}" ]]
do
sleep ${interval}
done
done
echo "All required files found."
will keep looping until it finds all files in required_files? Also, I'm guessing the rest of the code comes after the loops (after the last done statement). Thanks.
yes .. u r correct .. be sure that the file which u r checking for, is stable. i.e if u r getting the file at runtime then the condition " if [ -a $filename ] " will be successful even when the file is being copied in the directory, where u r looking the file for.
Quick question then. Why doesn't this code work? It keeps giving me a syntax error:
";" unexpected
Can this instance of the if statement only validate two conditions about the same file, and not check existence of one file and then existence of another?
myfile=/path/to/file
myfile2=/path/to/second/file
while true
do
if [[ -a $myfile && -a $myfile2]]; then
echo "$myfile exists!"
echo "$myfile2 exists!"
rest of code
else
sleep 600
fi
done