我有一个脚本可以将文件从目录上传到 s3 存储桶。
我的剧本是这样的
aws s3 sync <directory_of_files_to_upload> s3://<bucket-name>/
当我运行这个脚本时,整个文件都会正确上传。我想在上传新文件时运行这个脚本,所以我决定使用 inotify
我的脚本是这样的
#!/bin/bash
inotifywait -m -r -e create "<directory_of_files_to_upload>" | while read NEWFILE
do
aws s3 sync sunshine s3://turnaround-sunshine/
done
我的问题是两个方面
1.当我运行这个脚本时,它会接管终端,所以我不能做任何其他事情
[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.
它在我从本地上传文件但不上传整个文件时运行。ec2 中的文件是 2.7MB,但在 s3 中只有 ~350KB。当我自己运行 aws 命令而不进行 inotify 时,它可以正常工作(整个文件被上传)。当我将文件上传到受监控的目录时,程序也会输出(如下)。
上传:sunshine/turnaroundtest.json 到 s3://turnaround-sunshine/turnaroundtest.json