Skip to content

Instantly share code, notes, and snippets.

@cernoel
Created March 6, 2022 11:22
Show Gist options
  • Save cernoel/ce19762f426b45c9231f6e511cda7196 to your computer and use it in GitHub Desktop.
Save cernoel/ce19762f426b45c9231f6e511cda7196 to your computer and use it in GitHub Desktop.
check receiving of a new file via filedate
#!/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