0

I have a script that takes in a unique location number from a file. These are formatted like this 7325-05, 5269-09 and 7479-14, for example. The first four numbers are what the folder is called and the second number is the first two characters of the filename unique within each folder.

So I wrote this script to use locate and find to get the full path of the folder and then use a wildcard to download the specific file using rsync. Here's the script that I have right now:

#!/bin/bash

#IFS='
#'
oIFS=$IFS
IFS=$'\n'

while read line;
do
    name=$line;
    folder=${line:0:4}
    track=${line: -2}
    folderlocation="$(locate -r '/'$folder'$')"
    filelocation="$(find "$folderlocation" -type f -name "$track*")"
    rsync -vazhn --progress "$filelocation" /cygdrive/c/
#    mkdir /cygdrive/c/test/"$folder"
#    cp -rvi "$filelocation" /cygdrive/c/test/"$folder"

    echo "";
done < $1

The code using cp that is commented out works just fine. I would just really prefer to use rsync, mainly due to better feedback and more accurate progress reporting, as far as I can tell.

Using the code as pasted above (with rsync) throws this error:

./filelocator classic-locations.txt
sending incremental file list
rsync: change_dir "/home/emil//\\sandrew-nas/SMMUSIC/MMIMUSIC/7001-8000/7201-7300/7252/Unknown Album (29-12-2012 09-52-02)" failed: No such file or directory (2)

sent 20 bytes  received 12 bytes  64.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

sending incremental file list
rsync: change_dir "/home/emil//\\sandrew-nas/SMMUSIC/MMIMUSIC/7001-8000/7201-7300/7252/Unknown Album (29-12-2012 09-52-02)" failed: No such file or directory (2)

sent 20 bytes  received 12 bytes  64.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

As you can see, my home folder (where I issue the command) is suddenly included in the script, leading me to believe that a variable or wildcard is being expanded in the local shell, but no amount of escape characters seem to accomplish what I want with rsync.

Emil Visti
  • 55
  • 1
  • 6
  • Have you tried putting your file path in the inner quotes `"'$filelocation'"` – NarūnasK Jul 02 '15 at 09:50
  • @NarūnasK: Yes, I tried that as well with almost the same result: `sending incremental file list rsync: change_dir "/home/emil//'\\sandrew-nas/SMMUSIC/MMIMUSIC/7001-8000/7201-7300/7252/Unknown Album (29-12-2012 09-52-02)" failed: No such file or directory (2)` – Emil Visti Jul 02 '15 at 10:09
  • What about `find "$folderlocation" -type f -name "$track*" -print0 -exec rsync -0 -vazhn --progress {} /cygdrive/c/ \;` – NarūnasK Jul 02 '15 at 10:12
  • @NarūnasK: Almost the same thing.. `\\sandrew-nas/SMMUSIC/MMIMUSIC/1001-2000/1201-1300/1283/Classical/02 clarinet concerto in a major - slow movement - andante k622 -alexander grigorov, clarinet. the vienna chamber orchestra.wavsending incremental file list rsync: change_dir "/home/emil//\\sandrew-nas/SMMUSIC/MMIMUSIC/1001-2000/1201-1300/1283/Classical" failed: No such file or directory (2) ` – Emil Visti Jul 02 '15 at 10:37
  • Are you sure that this path `/home/emil//\\sandrew-nas/SMMUSIC/MMIMUSIC/1001-2000/1201-1300/1283/Classical` is valid on your system? I'm concerned about the `\\sandrew....` bit (note two *backslashes* in the filename). – NarūnasK Jul 02 '15 at 11:25
  • @NarūnasK - It's not valid at all. The \\sandrew etc. is valid – It's an smb share. The whole problem is that the /home/emil// is being introduced somewhere. It's the folder I run the script from. – Emil Visti Jul 02 '15 at 12:45
  • You are trying to access `smb` shares incorrectly.. Either `mount` it somewhere on your system or use `smbclient`. BTW, if this path is invalid `cp -rvi "$filelocation" /cygdrive/c/test/"$folder"` should be failing too. – NarūnasK Jul 02 '15 at 13:12
  • @NarūnasK: I don't know what to tell you, the cp version works perfectly. Not only that, I've been using scripts with rsync from the same locations and they've been working. It's only this specific script throwing errors. – Emil Visti Jul 02 '15 at 14:26

0 Answers0