I've got a bash script that rsync's two directories. Sometimes there's a change, odds are there's nothing.

I want to run a command only if rsync actually made a change (add/update a file). Otherwise I want to just skip it. Is there a return response I should be looking at?

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

If you use the -i option (and don't use the -v option), rsync will only print lines to STDOUT for any changes that were made. Depending on your script, this could look like

if [ `rsync -i /dir1 /dir2 | wc -l` == '0' ]; then
  run_command;
fi
link|improve this answer
That seems to do exactly what I want... thanks. Didn't think of using the -i flag like that. – raccettura Jun 30 '10 at 16:51
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.