Last active
April 8, 2020 16:58
-
-
Save serverabuse/5e8bc889e6f5d29a4d286d043383019c to your computer and use it in GitHub Desktop.
inotify s3 sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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