Publication date: 2020-06-30
Create a script wrapping rsync on the destination host. I executes arbitrary commands (example here: "touch /tmp/rsync-after"). stdin, stdout, stderr are redirected to avoid confusing any other scripts that rely on usual rsync behavior.
#!/bin/bash
/usr/bin/rsync "$@"
result=$?
(
if [ $result -eq 0 ]; then
touch /tmp/rsync-after;
fi
) >/dev/null 2>/dev/null </dev/null
exit $result
Make the script executable.
On the source host, this script needs to be specified using the "rsync-path" parameter so that it gets used as rsync executable on the destination host:
rsync -a --rsync-path=/path_to_script/rsyncafter.sh localfile desthost:
This is based on a script that was published for lsyncd. Link: http://axkibe.github.io/lsyncd/faq/postscript/.