Skip to content

Instantly share code, notes, and snippets.

@nmukerje
Created February 7, 2018 21:15
Show Gist options
  • Save nmukerje/aa1e85d6eb39d1b57d483606cf3e91d5 to your computer and use it in GitHub Desktop.
Save nmukerje/aa1e85d6eb39d1b57d483606cf3e91d5 to your computer and use it in GitHub Desktop.
Syncs files from EC2 to S3.
#!/bin/bash
BUCKET='<bucket>/sqoop/'
function upload() {
local path=$1
local file=$2
echo $path$file
aws s3 cp $path$file s3://$BUCKET$file &
}
inotifywait -q -e close_write /tmp/logs/sqoop/ -m |
while read action_dir event_list action_file; do
if [ -f "$action_dir$action_file" ]; then # only process a file, not a directory
case "${event_list}" in
CLOSE_WRITE* )
upload "$action_dir" "$action_file" > /dev/null 2>&1
;;
esac
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment