#!/bin/sh
# get the current path
 CURPATH=`pwd`
 
inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
 -e close_write /tmp/test | while read date time dir file; do
FILECHANGE=${dir}${file}
 # convert absolute path to relative
 FILECHANGEREL=`echo "$FILECHANGE" | sed 's_'$CURPATH'/__'`
rsync --progress --relative -vrae 'ssh -p 22' $FILECHANGEREL usernam@example.com:/backup/root/dir && \
 echo "At ${time} on ${date}, file $FILECHANGE was backed up via rsync"
 done


syntax highlighted by Code2HTML, v. 0.9.1