I have a script to upload a file from a directory to an s3 bucket.
My script is this
aws s3 sync <directory_of_files_to_upload> s3://<bucket-name>/
And when I run this script the whole file is uploaded properly. I want to run this script whenever a new file is uploaded so I decided to use inotify
my script is this
#!/bin/bash
inotifywait -m -r -e create "<directory_of_files_to_upload>" | while read NEWFILE
do
aws s3 sync sunshine s3://turnaround-sunshine/
done
My problem is two fold
1.When I run this script is takes over the terminal so I can't do anything else as such
[ec2-user@ip-xxx-xx-xx-xx s3fs-fuse]$ ./Script.sh
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
It runs when I upload a file from local but doesn't upload the entire file. The file in ec2 is 2.7MB but only ~350KB in s3. And it works properly (whole file gets uploaded) when I run the aws command myself without inotify. Also the program outputs (below) when I upload a file to the monitored directory.
upload: sunshine/turnaroundtest.json to s3://turnaround-sunshine/turnaroundtest.json