Created
March 6, 2022 11:22
-
-
Save cernoel/ce19762f426b45c9231f6e511cda7196 to your computer and use it in GitHub Desktop.
check receiving of a new file via filedate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
filename="./my-file" | |
waitseconds=30 | |
now=$(date +%s) | |
timeout=$(( now + waitseconds )) | |
file_modified=$(stat -c '%Y' $filename) | |
echo "wait for $filename ... time: $wait" | |
# check if file $filename is older than 30 seconds | |
# we assume, that when it is older than 30 seconds, we have an old file, we wait for a new one | |
while [[ $(( ($(date +%s) - $file_modified) > (waitseconds) )) == 1 ]] | |
do | |
# if now is > timeout, exit, else we wait a little bit | |
if [[ (( $(date +%s) -ge $timeout )) ]]; then exit 1; fi; | |
sleep 5 | |
file_modified=$(stat -c '%Y' $filename) | |
done | |
echo "found new file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment