I have this simple code
#!/bin/bash
TIMEOUT=60
# call a function that creates a file
LOG_FILE_NAME="/dir/something.txt"
create_a_file(LOG_FILE_NAME)
until [ ! -f ${LOG_FILE_NAME} ] || [ "$TIMEOUT" == "0" ]
do
echo "Slept 1 second while waiting for file creation"
sleep 1
((TIMEOUT--))
done
for file in $(ls -tr /dir/*.txt); do
#something
done
Most times this works but sometimes I get:
ls: cannot access /dir/*.txt: No such file or directory