2

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 [email protected] "cd /path/to/logs && find . -mtime -1 -print0" | rsync --from0 --files-from=- -avHS "[email protected]:/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!

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

1 Answer 1

4

Try

ssh -qx [email protected] "ls -t /path/to/logs | head -6" | rsync --files-from=- -avHS [email protected]:/path/to/logs/ . 
1
  • 1
    Thanks! The exact syntax that worked for me was: ssh -qx [email protected] "ls -t /path/to/logs | head -6" | rsync --files-from=- -avHS [email protected]:/path/to/logs/ . Commented Mar 19, 2018 at 18:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.