Skip to content

Instantly share code, notes, and snippets.

@gullevek
Created February 7, 2020 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gullevek/8fd3c819c97edd6fe265d909c92b84e0 to your computer and use it in GitHub Desktop.
Save gullevek/8fd3c819c97edd6fe265d909c92b84e0 to your computer and use it in GitHub Desktop.
Loops over files in a folder and checks if they changed. If they stay the same in 3 loops of 5s wait the script will end
#!/bin/bash
folder=${1};
diff=1;
sleeptime=5;
if [ ! -d "${folder}" ]; then
echo "Folder: ${folder} not found";
exit;
fi;
declare -A file_sizes;
echo "[START CHECK]";
# get all files in this folder so we can stat them for size
for file in $(ls -1 ${folder}/); do
file_sizes[${file}]=$(stat -c %s "${folder}/${file}");
done;
while [ ${diff} -eq 1 ]; do
diff=0;
echo -n "<$(date +"%F %T")>(";
for i in $(seq 1 3); do
echo -n "#";
for file in $(ls -1 ${folder}/); do
size=$(stat -c %s "${folder}/${file}");
or_size=${file_sizes[${file}]};
#echo "FS: "${file_sizes[${file}]}" = "${size};
if [ ${or_size} -ne ${size} ]; then
diff=1;
fi;
echo -n ${diff};
file_sizes[${file}]=${size};
done;
# wait
sleep ${sleeptime};
done;
echo ")";
done;
echo "";
echo "[DONE: Sizes have not changed in the last ${sleeptime} seconds in ${folder}]";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment