Bug 3787 - Optional exit code indicating receiver was changed
Summary: Optional exit code indicating receiver was changed
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 2.6.9
Hardware: Other All
: P3 normal (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
Depends on:
Reported: 2006-05-18 16:06 UTC by Matt McCutchen
Modified: 2006-05-30 15:22 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Matt McCutchen 2006-05-18 16:06:29 UTC
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.
Comment 1 Wayne Davison 2006-05-30 15:22:39 UTC
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
    echo rsync copied no files

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:

open(RSYNC, '-|', 'rsync -ai popt /var/tmp/') or die $!;
while (<RSYNC>) {
    $found = 1 if /^[<>]f/;
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.