Skip to content

Instantly share code, notes, and snippets.

@serverabuse
Last active April 8, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serverabuse/5e8bc889e6f5d29a4d286d043383019c to your computer and use it in GitHub Desktop.
Save serverabuse/5e8bc889e6f5d29a4d286d043383019c to your computer and use it in GitHub Desktop.
inotify s3 sync
#!/bin/bash
watchdir=/home/vagrant
logfile=/home/vagrant/watcher.log
while : ; do
inotifywait $watchdir|while read path action file; do
ts=$(date +"%C%y%m%d%H%M%S")
echo "$ts :: file: $file :: $action :: $path">>$logfile
if [[ $action == "CREATE,ISDIR" || $action == "CREATE" || $action == "DELETE" || $action == "MODIFY" ]]; then
aws s3 sync s3://$TARGET_BUCKET $watchdir
exitcode=$(echo $?)
if [ exitcode -ne 0]; then
echo "[ERROR] Failed s3 sync. Program exited with status code $exitcode" >> $logfile
fi
fi
done
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment