#!/bin/bash# Get the current userCURRENT_USER="$USER"# Source and destination foldersSOURCE_FOLDER="/path/to/source/folder"DESTINATION_HOST="username@destination_host"DESTINATION_FOLDER="/path/to/destination/folder/$CURRENT_USER"# Log fileLOG_FILE="/path/to/log/file.log"# Function to sync files using rsyncsync_files(){rsync-avz--delete"$SOURCE_FOLDER/""$DESTINATION_HOST:$DESTINATION_FOLDER/"}# Function to log changeslog_change(){echo"$(date): Change detected by $CURRENT_USER - $1$2">>"$LOG_FILE"}# Monitor changes using inotifywaitwhiletrue;do
inotifywait -r-e modify,create,delete,move "$SOURCE_FOLDER"|whileread path action file;do
log_change "$action""$file"
sync_files
donedone
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
sending incremental file list
./
text.txt
sent 110 bytes received 38 bytes 98.67 bytes/sec
total size is 0 speedup is 0.00
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.