1

Long time reader, first time poster.

I'm trying to rsync the latest few log files from a remote server to my laptop. I've gotten close with this:

ssh -qx root@example.org "cd /path/to/logs && find . -mtime -1 -print0" | rsync --from0 --files-from=- -avHS "root@example.org:/path/to/logs/" .

But that syncs all the files from the past day, which is too many. Ideally I'd like to just download the last half dozen or so files. I know this will list the latest 6 files:

ls -t|head -6

But I'm not sure how to use these two bits of info together (if it's even possible) to solve my problem. Thanks in advance!

  • did you try ssh -qx root@example.org " ls -t /path/to/logs | head -6 " | rsync.... ? – Putnik Mar 17 '18 at 7:35
  • Amazing, thank you! I played with it and this worked: ssh -qx root@example.org "ls -t /path/to/logs | head -6" | rsync --files-from=- -avHS root@example.org:/path/to/logs/ . – john Mar 17 '18 at 16:12
  • 1
    I've converted my comment to answer, please accept if it works for you. – Putnik Mar 18 '18 at 7:22
1

Try

ssh -qx root@example.org " ls -t /path/to/logs | head -6 " | rsync ....
  • Thanks! The exact syntax that worked for me was: ssh -qx root@example.org "ls -t /path/to/logs | head -6" | rsync --files-from=- -avHS root@example.org:/path/to/logs/ . – john Mar 19 '18 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.