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:
1112223334_18BEwW4data
First student number (1112223334), then _class (_18BE), then week number (wW4 = winter term Week 4) plus data
The paths are:
RemotePath="public_html/18BE/php/uploads"
Answers="/home/pedro/winter2019-20/18BE/fastmarker"
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!"
exit
fi
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!