0
votes

On my server, I have x number of sub-domains Their folder names are like this:

example1.mydomain.com , example2.mydomain.com,  examplex.mydomain.com

and they all exist in one location.

I am trying to write a simple bash script to copy all folders and files in folder SOURCE for example to all of those sub-domain folders (and replace existing).

In other words, I want to copy my files from source to any folder with the name *.mydomain.com

I tried rsync but couldn't do the *.mydomain part

2
What exactly is the problem when using rsync?Raman Sailopal
for i in *.mydomain.com; do rsync -aSv "SOURCE/" "$i"; done?Cyrus
@Cyrus am checking it nowRichardLops81
@Cyrus this worked perfectly thanks a lot for your help I wasn't using the for, Can you post it as an answer?RichardLops81

2 Answers

0
votes

You can use find command to search all files and then use this output to copy them, e.g. assuming you are searching in /home and copying to /target

    find /home -name "*.mydomain.com" -exec cp -r {} /target/  \;

But one problem in above solution I see is it might find files / folders with these names and copy them none the less (not sure if it will maintain the same folder hierarchy), perhaps IF you are only looking for folder then try below instead,

    find /home -name "*.mydomain.com" -type d -exec cp -r {} /target/  \;
0
votes

I suggest:

for i in *.mydomain.com; do rsync -aSv "SOURCE/" "$i"; done

The trailing / after SOURCE is important.