Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've got a server where I do my web development and testing, and I have a bunch of frontend servers that sit behind a load balancer. I wrote a simple bash script to rsync a directory on my dev server to all of the production servers when I fix a bug, etc.

The rsync APPEARS to work, but when I actually go to the other servers, none of the files have been updated. What am I doing wrong?

#!/bin/bash

directory=$1

echo "$directory"

set -x
for host in "xxx.xxx.xxx.xxx"
do
    rsync -avz -e ssh ${directory} root@${host}:${directory}
done

At the moment I only have one ip address in the for loop, but I'll be adding more as time goes on. This is how I'm executing the script and the abbreviated output:

[root@admin vhosts]# ./rsync_to_frontend.sh /var/www/scripts
/var/www/scripts
+ for host in '"xxx.xxx.xxx.xxx"'
+ rsync -avz -e ssh /var/www/scripts root@xxx.xxx.xxx.xxx:/var/www/scripts
sending incremental file list
scripts/
scripts/fetchTweets.php
scripts/syncMediaFiles.log
scripts/syncMediaFiles.php
.....

sent 7395053 bytes  received 1252 bytes  2113230.00 bytes/sec
total size is 36718000  speedup is 4.96
[root@admin vhosts]#

If I run the command again, rsync appears to work appropriately and as expected does not show any files in the list, ostensibly because they've all been updated. However, when I go and look at the files on server xxx.xxx.xxx.xxx, they haven't been updated at all.

share|improve this question

migrated from stackoverflow.com Jun 14 '13 at 17:17

This question came from our site for professional and enthusiast programmers.

    
pick one file and find it in the destination, I think you are looking at (copying) to the wrong folder –  perreal Jun 12 '13 at 23:44
    
Hm, you're right. I wonder if this has to do with having a trailing slash on ${directory} –  Kenny Wyland Jun 13 '13 at 0:03
    
these are equivalent: rsync -av /src/foo /dest, rsync -av /src/foo/ /dest/foo –  perreal Jun 13 '13 at 0:06
    
Right, my problem was occurring when I did rsync -av /src/foo user@host:/src/foo which was duplicating the directory as you suggested, creating /src/foo/foo –  Kenny Wyland Jun 13 '13 at 0:08
add comment

1 Answer

Due to the strict requirements on trailing slashes when using rsync, I just needed to make sure to put a trailing slash when rsyncing a directory:

Bad:

# ./rsync_to_frontend.sh /var/www/scripts

vs Good:

# ./rsync_to_frontend.sh /var/www/scripts/
share|improve this answer
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.