I'm trying to copy the contents of the newest directory from a remote server to a local server. Problem is that the directory names are date based, so it can't be static value in the command. I'd like to run the command from a cron as well so I'm hoping this is possible without some script.
Remote directory example (ls):
/directory/backups
.
..
2017-09-23/
2017-09-24/
2017-09-25/
weekly/
So in this case, I'd like to copy the contents of the 2017-09-25 directory as that is the newest and both name and modified stamp are same date.
To give a visual example:
rsync -chavzP --stats root@0.0.0.0 /directory/backups/(ls -td -- */ | head -n 1) /my_local_dir
Is there a way to do this with rsync or even scp?
Edit:
I realize this may seem like a trivial task. However, there are several reasons why I am seeking a way to do the copy in this manner. I've searched quite a bit but have not found anything to make it clear to me how to write the command to copy using either rsync or scp or whether it is even possible. My command-line-fu is basic.