Created
February 7, 2020 02:32
-
-
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
This file contains hidden or 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 | |
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