2

I have a simple task that I can do with multiple lines but I wanted to run this through just 1 cron job as 1 line, and not have 12 separate lines. Here is the setup:

Have one folder on an image processing share that gets images and moves them to 12 different folders depending on location and other things. Folder names are 1a, 2a, 3a, 4a, 5a, 6a, etc. to 12a. Folders 1a-6a need to go to a mounted drive on dr01 and folders 7a-12a need to go to a mounted folder named dr02. Each of the #a folders have a lot of subfolders and files inside.

So, I want to rsync ../images/1a to ..DR01/1a twice a day. I can do this for each folder individually with:

rsync -avh --remove-source-files /images/1a/ /usr/local/blah/dr02/1a/

I wish that I could just sync the entire directory, but since half of the files are going to one share and the other half to another, I have to break them up.

Is there a better way to do this without having to create 12 rsync jobs to sync each folder? Is there a way to group them in the rsync line or something like that? I used to use union-fs to fuse the DRs together, but that is no longer a working option.

Thanks in advance for any tips that can help me resolve this issue.

3
2

Something like this might work for you, assuming a shell that can expand {x..y} type constructs. (Test it from the command-line by prefixing the entire line with echo.)

rsync -avh --remove-source-files /images/{1..6}a /mnt/dr01/
rsync -avh --remove-source-files /images/{7..12}a /usr/local/blah/dr02/
3
  • 1
    @drewbenn yes [1-6]a will work, but [7-12]a won't. In the interests of avoiding possible confusion over punctuation I chose to keep the same constructs for both expansions.
    – roaima
    May 30 '17 at 22:54
  • @roaima awesome -- I think that this may be what im looking for. But, if the destination has matching folders for each file, how would I specify those? I'll edit main question for example
    – saleetzo
    May 30 '17 at 23:57
  • the dry run looks like it moves them to the correct folder!!! awesome! thanks. Would I be able to do this with alpha numbers as well? for instance, instead of it being 1a, 2a, 3a... it was Aa, Ba, Ca. Would {A..C}a work as well?
    – saleetzo
    May 31 '17 at 0:14

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.