I'm trying to write a short shell script which also handles copying a file called webcam.jpg
into a date coded subdirectory. I'm using rsync for this as it automatically creates a directory if it doesn't already exist.
Everything works fine when I use:
rsync -a webcam.jpg ./$(date +%Y-%m-%d)/$(date +%Y-%m-%d_%H-%M).jpg
But when going one directory deeper, rsync starts throwing errors, and I really don't have a clue why. I'm typing:
rsync -a webcam.jpg ./saved_images/$(date +%Y-%m-%d)/$(date +%Y-%m-%d_%H-%M).jpg
and my output is:
rsync: change_dir#3 "/var/www/tmp/test//./saved_images/2013-07-07" failed: No such file or directory (2)
rsync error: errors selecting input/output files, dirs (code 3) at main.c(677) [Receiver=3.0.9]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]
I see the relevant error in the first line, but why is rsync trying to access this test//./saved_images
directory in the first place? What's wrong with test/saved_images/
?
Best Answer
Ok
/var/www/tmp/test//./saved_images/2013-07-07
is the same as/var/www/tmp/test/saved_images/2013-07-07
.Double
/
are ignored you can typels ////
and it is the same asls /
.The dot
.
is the same directory it is in. Sols /.
shows the same output asls /
and so/var/www/tmp/test/.
points to the directory/var/www/tmp/test/
.So
rsync
just takes the current directory it is in, in you casevar/www/tmp/test/
(at least when your path starts with a.
). Then its adds an extra/
so it can make sure that the path it definitely has a/
add the end. In the last step its adds the part you gave it, here./saved_images/$(date +%Y-%m-%d)/$(date +%Y-%m-%d_%H-%M).jpg
The error you are seeing is that the directory
/var/www/tmp/test/saved_images/
is not there andrsync
will not create it, because it seams thatrsync
only creates one directory.Edit
Maybe for your problem you should just use a script with