I should say I'm only an amateur at this. The following gets homework files from my webpage. Works well.

rsync -av --progress -e 'ssh -i ~/.ssh/godaddy5_rsa' $user@$server:${RemotePath}/ "${Answers}"

All the file names look like this:


First student number (1112223334), then _class (_18BE), then week number (wW4 = winter term Week 4) plus data

The paths are:


Of course, as the term proceeds, wWX will change. I made a little bash script to get the week number and inserted it in my script for rsync:

echo "First, enter the week number you want to get."
read week
echo "You are fetching winter week $week"
echo "If this is correct, enter y, if not enter n to abort."
read answer
if [ $answer = "n" ]; then
echo "You entered the wrong week number, aborting script, byebye. Start again!"
echo "You entered the correct week number, I'll carry on!"

Now I want to only get files which have $week in the name, for next week that will be wW4.

I have been reading the rsync manpage and trying all kinds of combinations of --include and --exclude

All I ever get is either nothing or all files, i.e. files which also have wW1, wW2 and wW3 in the file name.

How should I tell rsync to only get files with $week (next week will be wW4) in the name??

EDIT: Thanks for the suggestion. I tried this:

rsync -av --progress -e 'ssh -i ~/.ssh/godaddy5_rsa' $user@$server:${RemotePath}/*_18BEwW4data "${Answers}"

Sadly, I get nothing. I need a wildcard for the student numbers, because they are all different.

I renamed some file to end in *.wW4 then I tried this:

rsync -av --progress -e 'ssh -i ~/.ssh/godaddy5_rsa' $user@$server:${RemotePath}*.wW4 "${Answers}"

I get this error in bash:

Third, get the files from the remote server to this computer. receiving incremental file list rsync: link_stat "/home/myusername/public_html/18BE/php/uploads*.wW4" failed: No such file or directory (2)

sent 8 bytes received 123 bytes 15.41 bytes/sec total size is 0 speedup is 0.00 rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1668) [Receiver=3.1.2] pedro@pedro-school2:~$

SORRY! My fault! I had a mistake in the $RemotePath it works now!

Thanks, and sorry to bother you!

rsync -av --progress -e 'ssh -i ~/.ssh/godaddy5_rsa' $user@$server:${RemotePath}/1112223334_18BEwW4* "${Answers}"

Don't overthink this, you don't need include/exclude, you just need wildcards.

You really don't need even to figure out the week since you can just have a directory that has all the assignments in it, and rsync will just grab the newest, like so:

rsync -av --progress -e 'ssh -i ~/.ssh/godaddy5_rsa' $user@$server:${RemotePath}/1112223334_18BEwW* "${Answers}"

date +%U will return the week of the year, so you can use that to generate automatically the week of the course, assuming it's linear, incrementing 1 every week. Or you can make an array where the indexes point to the course week number, and the indexes are the year week number. Or if it's a linear relation, you just add/subtract whatever to the year week number.

  • Thanks, but that did not work for me. I need a wild card for the student numbers, because they are all different.
    – Pedroski
    Sep 21 '19 at 8:12
  • You didn't say that you needed different student numbers. Then just replace any part you want to be wild carded with a wild card. $user@$server:${RemotePath}/*_18BEwW* or whatever. When asking the question, the more precise you are about is actually required, the easier it is to answer it fully the first time.
    – Lizardx
    Sep 21 '19 at 21:51

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.