I'd like an option that causes rsync to exit with a distinctive exit code, say 26, if everything is successful and one or more files on the receiver were changed (or would have been changed if --dry-run had not been used). If nothing on the receiver was changed, rsync should exit 0. If rsync had this option, makefiles could implement better dependency logic for commands that operate on large file trees by using rsync to detect whether a file tree has changed. Specifically, my Web site's build system calls rsync once to collect the files to be posted into a temporary folder and again to push the temporary folder to the server I'm using. I'd like to skip the second rsync if the first rsync does not modify the temporary folder.
It seems to me that it would be just as easy to ask rsync to itemize the changes (see -i) and then filter the output. For instance: if rsync -ai /src/ /dest/ | grep '^[<>]f' >/dev/null; then echo rsync copied one or more files else echo rsync copied no files fi Or, if you need to see the output, substitute something like a perl script for the grep. Here's one that runs an rsync command (complete with output) and sets the return code as appropriate: #!/usr/bin/perl open(RSYNC, '-|', 'rsync -ai popt /var/tmp/') or die $!; while (<RSYNC>) { $found = 1 if /^[<>]f/; print; } close RSYNC; $status = $? >> 8; exit($found ? 26 : $status); Both these options give you full control over what you consider important. For instance, the above checks only consider updated files important. You could have different exit codes for updated permissions, updated symlinks, or whatever you need.