Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 6 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
share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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