I had followed several threads here in SO to copy files from one directory to another. I am using inotifywait for my purposes which is working perfectly for all BUT one scenario. It's also copying files that start with a DOT prefix (ex .tmp.swp) which I don't want.
I tried this but this even causing files with the -json postfix to NOT get copied.
I don't want .tmp.abcd-json to be copied. If I remove the check AFTER the && everything is getting copied over including the .tmp.abcd-json:
These are some of the contents of the directory. The .tmp ones are unwanted but it's not ALWAYS guaranteed they will always start with .tmp. I've seen other files start with . prefixes randomly which also need to be ignored:-
abcd-json
.tmp.abcd-json
#!/bin/sh
dir=/var/lib/docker/containers
target=/var/log/splunkf
inotifywait -m -r "$dir" --format '%w%f' -e create -e modify \
| while read file;
do
if [[ $file == "-json"* ]] && [[ $file != "."* ]];
then
echo Copying $file to $target
cp -- "$file" "$target";
else
echo NOT Copying $file to $target
fi
done