0

I'm writing a script that will utilize rsync to push from a master sever to several child nodes. I won't bore you with most of my script (though in my Ruby infancy I'm especially proud of it), but I'm running into an issue when Ruby runs the rsync binary. I've rsync standalone with the same parameters and it work, but does not work through the script. Here's the output I get:

rsync: link_stat "/Shared Items/Share/\#012" failed: No such file or directory (2)
rsync: push_dir#3 "/Users/ckbrumb/Desktop/Projects/ruby_sync/@/Shared Items/Share" failed: No such file or directory (2)
rsync error: errors selecting input/output files, dirs (code 3) at /SourceCache/rsync/rsync-42/rsync/main.c(580) [receiver=2.6.9]
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [sender=2.6.9]

And here's that portion of the script:

def perform_sync

    File.foreach(@filename) do |line|

        serv_path_array = line.split(":")
        shr_server = serv_path_array[0]
        shr_path = serv_path_array[1]
        shr_user = serv_path_array[2]

        `rsync -avrpogz --delete -e ssh "#{@master_share}" "#{shr_user}@#{shr_server}:#{shr_path}"` 
    end
end

@master_share is an initialized variable set by reading the first line of preference file the script lays down during its first run. It returns the proper path in all testing. For the destination share (shr_user@shr_server:shr_path), the rest of the lines of that file are formatted like so: <serverName>:<user>:<path>. The script splits this line with the : as the delimiter and the variables are set based on the associated position in the array.

For the first line of the error, I've tried both having no \ to escape the space and leaving it as is with the same result in both cases. The \#012 is throwing me off, but I've yet been unable to track that (escape code?) down.

For the "error in protocol datastream" issue, I did see Why is this rsync connection unexpectedly closed on Windows? that mentions rsync being in different locations on the servers. I'll look into that, however, I'm going from a 10.8.3 to a 10.8.3, and I've not messed with any binary locations, so it's almost impossible that that's the issue.

I've still have some research to do on this, but with the issue only existing when calling rsync from my script, I'm hoping someone sees what the problem is and can push me in the right direction.

UPDATE: Just made a little progress. The first part of the error is because of how the @master_share variable is passing the string. I took that out and put the path to the share directly in quotes and it got past that point. Now it hangs up when asking for a password. Will not accept the correct password. In the end I'm going to have a proper authorized_keys file set up, but for now I'm just entering the password when rsync asks for it while the script is running. Is it possible that the password I enter isn't being passed through the script to rsync?

Community
  • 1
  • 1
ckbrumb
  • 191
  • 2
  • 11
  • Just made a little progress. The first part of the error is because of how the @master_share variable is passing the string. I took that out and put the path to the share directly in quotes and it got past that point. Now it hangs up when asking for a password. Will not accept the correct password. In the end I'm going to have a proper authorized_keys file set up, but for now I'm just entering the password when rsync asks for it while the script is running. Is it possible that the password I enter isn't being passed through the script to rsync? – ckbrumb May 12 '13 at 13:49
  • Edit your question instead of posting a comment that is essentially amending your question. – Andrew Marshall May 12 '13 at 13:51
  • Thanks for the protocol tip. I wanted to leave the original post intact in case something in it was helpful to the newer issue. I'll edit it with the text from my comment at the bottom. Thanks again. – ckbrumb May 12 '13 at 13:57
  • I suggest you start by seeing if can just construct an `rsync` command that works as you like through bash, then worry about how to properly dispatch it from your ruby script. One piece of advice when you get there, the tokens-in-a-array form of [`system`](http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-system) [`spawn`](http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-spawn) or any of the [`Open3`](http://www.ruby-doc.org/stdlib-2.0/libdoc/open3/rdoc/Open3.html) variants is better than the one-string form at making sure the sub-command interprets args correctly. – dbenhur May 12 '13 at 22:33
  • Thanks for the tip. I thought I had mentioned it, but I've already constructed the command, fully working, in bash. I will try your suggestion regarding the way I build the command. – ckbrumb May 12 '13 at 23:02
  • @ckbrumb are you still having an issue? If you found that is was simple error (typo), then please delete the question. Otherwise, if you have a solution, then please _submit an answer_ and mark it as accepted. Not many people read the comments on SO. – onebree Aug 19 '15 at 15:22

0 Answers0